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

Allow access to Java inner classes with corresponding private Ruby methods #1871

Closed
donv opened this issue Jul 30, 2014 · 1 comment
Closed

Comments

@donv
Copy link
Member

donv commented Jul 30, 2014

Hi!

Given the following Java class:

public final class ClassWithAttr {
    public static final class attr {
        public static final int value = 42;
    }
    public static final class id {
        public static final int value = 42;
    }
}

it should be possible to access the inner class attr using the syntax ClassWithAttr.attr. This works for ClassWithAttr.id, and you can get to the field using ClassWithAttr.id.value. This should work for ClassWithAttr.id.value as well, but currently fails with an exception:

$ rvm use jruby
Using /Users/uwe/.rvm/gems/jruby-1.7.13
$ javac ClassWithAttr.java 
$ irb
jruby-1.7.13 :001 > Java::ClassWithAttr.id.value
 => 42 
jruby-1.7.13 :002 > Java::ClassWithAttr.attr.value
NoMethodError: private method `attr' called for Java::Default::ClassWithAttr:Class
    from (irb):2:in `evaluate'
    from org/jruby/RubyKernel.java:1101:in `eval'
    from org/jruby/RubyKernel.java:1501:in `loop'
    from org/jruby/RubyKernel.java:1264:in `catch'
    from org/jruby/RubyKernel.java:1264:in `catch'
    from /Users/uwe/.rvm/rubies/jruby-1.7.13/bin/irb:13:in `(root)'

As a side note, on Ruboto we get a slightly different error message (ruboto/ruboto#654):

(NoMethodError) undefined method `attr' for Java::Android::R:Class
@donv donv added this to the JRuby 9000 milestone Jul 30, 2014
@donv donv added the core label Jul 30, 2014
@enebo enebo modified the milestone: JRuby 9.0.0.0 Jul 14, 2015
@kares
Copy link
Member

kares commented Apr 11, 2016

wondered where's that attr method coming from - initially thought its some internal of Java integration.
... but its a valid Module method (attr_reader alias): http://ruby-doc.org/core-2.3.0/Module.html#method-i-attr ... thus this won't fix, workaround: Module.send :remove_method, :attr

@kares kares closed this as completed Apr 11, 2016
@kares kares added this to the Won't Fix milestone Apr 11, 2016
kares added a commit to kares/jruby that referenced this issue Apr 11, 2016
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

3 participants