You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
The text was updated successfully, but these errors were encountered:
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.
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:
The same in sorting of an ArrayList in Java 8:
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.
The text was updated successfully, but these errors were encountered: