Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 8 not loading java_ext on JRuby 1.7.22 #3367

Closed
smellsblue opened this issue Oct 3, 2015 · 2 comments
Closed

Java 8 not loading java_ext on JRuby 1.7.22 #3367

smellsblue opened this issue Oct 3, 2015 · 2 comments

Comments

@smellsblue
Copy link
Contributor

I am getting different behavior with JRuby depending on which version of Java I am running.

It appears that jruby/java/java_ext/java_util.rb is not being loaded in Java 8, or probably more likely that ArrayList#sort is taking precedence over the sort method defined in java_util.rb.

I haven't tried this on JRuby 9000 yet, as we are trying to get to JDK 8 before tackling that upgrade.

Here is a demonstration of my problem. Sorting an ArrayList in Java 7:

ubuntu@new-server:~$ java -version
java version "1.7.0_79"
OpenJDK Runtime Environment (IcedTea 2.5.6) (7u79-2.5.6-0ubuntu1.14.04.1)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)

ubuntu@new-server:~$ java -jar jruby-complete-1.7.22.jar -S irb
irb(main):001:0> Java::JavaUtil::ArrayList.new.sort
=> #<Java::JavaUtil::ArrayList:0x168b1b21>
irb(main):002:0> Java::JavaUtil::ArrayList.new.sort { |x, y| x <=> y }
=> #<Java::JavaUtil::ArrayList:0xf558f49>
irb(main):003:0> Java::JavaUtil::ArrayList.new.method(:sort)
=> #<Method: Java::JavaUtil::ArrayList(Java::JavaUtil::List)#sort>
irb(main):004:0> Java::JavaUtil::ArrayList.new.method(:sort).source_location
=> ["file:/home/ubuntu/jruby-complete-1.7.22.jar!/jruby/java/java_ext/java.util.rb", 146]

The same in sorting of an ArrayList in Java 8:

ubuntu@new-server:~$ java -version
openjdk version "1.8.0_45-internal"
OpenJDK Runtime Environment (build 1.8.0_45-internal-b14)
OpenJDK 64-Bit Server VM (build 25.45-b02, mixed mode)

ubuntu@new-server:~$ java -jar jruby-complete-1.7.22.jar -S irb
irb(main):001:0> Java::JavaUtil::ArrayList.new.sort
ArgumentError: wrong number of arguments (0 for 1)
    from (irb):1:in `evaluate'
    from org/jruby/RubyKernel.java:1079:in `eval'
    from org/jruby/RubyKernel.java:1479:in `loop'
    from org/jruby/RubyKernel.java:1242:in `catch'
    from org/jruby/RubyKernel.java:1242:in `catch'
    from /home/ubuntu/jruby-complete-1.7.22.jar!/META-INF/jruby.home/bin/jirb:13:in `(root)'
irb(main):002:0> Java::JavaUtil::ArrayList.new.sort { |x, y| x <=> y }
=> nil
irb(main):003:0> Java::JavaUtil::ArrayList.new.method(:sort)
=> #<Method: Java::JavaUtil::ArrayList#sort>
irb(main):004:0> Java::JavaUtil::ArrayList.new.method(:sort).source_location
=> nil

If this is something that is desired to be fixed, I can try tackling a fix myself, but if it is intended to be non-supported behavior on Java 8 + JRuby 1.7, I could probably try the upgrade of JRuby 9000 before my JDK upgrade.

@kares
Copy link
Member

kares commented Oct 6, 2015

it will behave the same on 9K ... its an unfortunate name collision but a "fix" would get kind of ugly.
if there's a java method on a class users sure expect it to work even when it hides Ruby ones (e.g. java.lang.System.exit(0) is not expected to delegate to Ruby's Kernel#exit) - who's to decide which should re-def and which not (esp. if you consider that core Kernel methods might get "polluted" with gems such as active_support). in this case java.util.ArrayList includes its own sort impl on Java 8, that is why it's found and used before consulting methods from java.util.Collection.
with a simple java.util.ArrayList.class_eval ... patch you can change the behaviour.

@kares kares added this to the Won't Fix milestone Oct 6, 2015
@smellsblue
Copy link
Contributor Author

Fair enough, I suspected this might be the answer, closing now. Thanks for looking at it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants