Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Won't Fix
-
Affects Version/s: JRuby 1.6
-
Fix Version/s: None
-
Component/s: Java Integration
-
Labels:None
-
Environment:Arch Linux, Red Hat Enterprise Linux 5
-
Number of attachments :
Description
irb(main):001:0> require 'java'
=> true
irb(main):002:0> 1.to_java.class
=> Java::JavaLang::Long
irb(main):003:0> //.to_java.class
ArgumentError: wrong number of arguments (0 for 2)
from /opt/jruby/lib/ruby/1.8/irb.rb:310:in `output_value'
from /opt/jruby/lib/ruby/1.8/irb.rb:159:in `eval_input'
from /opt/jruby/lib/ruby/1.8/irb.rb:271:in `signal_status'
from /opt/jruby/lib/ruby/1.8/irb.rb:155:in `eval_input'
from /opt/jruby/lib/ruby/1.8/irb/ruby-lex.rb:244:in `each_top_level_statement'
from org/jruby/RubyKernel.java:1417:in `loop'
from /opt/jruby/lib/ruby/1.8/irb/ruby-lex.rb:230:in `each_top_level_statement'
from org/jruby/RubyKernel.java:1190:in `catch'
from /opt/jruby/lib/ruby/1.8/irb/ruby-lex.rb:229:in `each_top_level_statement'
from /opt/jruby/lib/ruby/1.8/irb.rb:154:in `eval_input'
from /opt/jruby/lib/ruby/1.8/irb.rb:71:in `start'
from org/jruby/RubyKernel.java:1190:in `catch'
from /opt/jruby/lib/ruby/1.8/irb.rb:70:in `start'
from /usr/bin/jirb:13:in `(root)'
Maybe IRB bug!!
There is no magical "conversion" that you might be expecting.
There is no corresponding class for the object in question, so we are doing our best, matching Java::org.jruby.RubyRegexp when #to_java is invoked on a Regexp.
My understanding is this:
When you try to print the class name via p, we call inspect on this Java class. But the method lookup fails; inspect takes 0 arguments in the Ruby land, but it requires 2 arguments in the Java land, which leads to the confusing error message.
It might be possible to anticipate this sort of situation and get around it, but it is not immediately obvious to me.