Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Not A Bug
-
Affects Version/s: JRuby 1.6.7
-
Fix Version/s: None
-
Component/s: Java Integration
-
Labels:None
-
Environment:Mac OS X 10.7.3
Java(TM) SE Runtime Environment (build 1.6.0_31-b04-415-11M3635)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01-415, mixed mode)
-
Number of attachments :
Description
In some specific circumstances, methods defined on Java classes are not callable from JRuby. I have observed this happening when the following things come together:
- the instantiated class is a subclass of another Java class,
- the superclass has default visibility,
- the superclass has a generic type parameter, and
- a method is defined on the superclass whose return type is the generic type parameter.
In these circumstances, JRuby thinks that this method does not exist. (It's particularly curious that if the method has a non-generic return type, the method is callable from JRuby!)
Example, using JRuby installed via Maven:
$ cat Superclass.java
class Superclass<T> {
private T proto;
public T getProto() { return proto; }
}
$ cat Subclass.java
public class Subclass extends Superclass<String> {}
$ javac Superclass.java Subclass.java
$ java -cp .:$HOME/.m2/repository/org/jruby/jruby-complete/1.6.7/jruby-complete-1.6.7.jar org.jruby.Main -S irb
irb(main):001:0> java_import Java::Subclass
=> Java::Default::Subclass
irb(main):002:0> Subclass.new.proto
NoMethodError: undefined method `proto' for #<Java::Default::Subclass:0x622f996f>
from (irb):2:in `evaluate'
from org/jruby/RubyKernel.java:1083:in `eval'
from file:/Users/martin/.m2/repository/org/jruby/jruby-complete/1.6.7/jruby-complete-1.6.7.jar!/META-INF/jruby.home/lib/ruby/1.8/irb.rb:158:in `eval_input'
from file:/Users/martin/.m2/repository/org/jruby/jruby-complete/1.6.7/jruby-complete-1.6.7.jar!/META-INF/jruby.home/lib/ruby/1.8/irb.rb:271:in `signal_status'
from file:/Users/martin/.m2/repository/org/jruby/jruby-complete/1.6.7/jruby-complete-1.6.7.jar!/META-INF/jruby.home/lib/ruby/1.8/irb.rb:155:in `eval_input'
from org/jruby/RubyKernel.java:1410:in `loop'
from org/jruby/RubyKernel.java:1183:in `catch'
from file:/Users/martin/.m2/repository/org/jruby/jruby-complete/1.6.7/jruby-complete-1.6.7.jar!/META-INF/jruby.home/lib/ruby/1.8/irb.rb:154:in `eval_input'
from file:/Users/martin/.m2/repository/org/jruby/jruby-complete/1.6.7/jruby-complete-1.6.7.jar!/META-INF/jruby.home/lib/ruby/1.8/irb.rb:71:in `start'
from org/jruby/RubyKernel.java:1183:in `catch'
from file:/Users/martin/.m2/repository/org/jruby/jruby-complete/1.6.7/jruby-complete-1.6.7.jar!/META-INF/jruby.home/lib/ruby/1.8/irb.rb:70:in `start'
from /Users/martin/Applications/jruby/bin/jirb:13:in `(root)'
The same exception occurs when trying to call get_proto or getProto.
Activity
Charles Oliver Nutter
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Assignee | Charles Oliver Nutter [ headius ] | |
| Resolution | Not A Bug [ 6 ] |
Charles Oliver Nutter
made changes -
| Status | Resolved [ 5 ] | Closed [ 6 ] |