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 reified classes to store instance variables in raw fields (fixed) #7150

Merged
merged 4 commits into from
Mar 22, 2022

Conversation

byteit101
Copy link
Member

See #7012 though now hopefully fixed

This is principally for making Java integration produce
more idomatic Ruby. This allows users to configure a class
to store specific ivars in a field of a reified class.
@headius
Copy link
Member

headius commented Mar 22, 2022

I have confirmed this will be green once merged with my Logger test fixes: https://github.com/jruby/jruby/actions/runs/2022952391

However I can't figure out why this example does not work... where is the field?

$ jruby -e 'class Foo < java.lang.Object; java_field "java.lang.String stringField"; end; f = Foo.new; puts f.class.java_class.declared_fields.to_a'
private final org.jruby.java.proxies.ConcreteJavaProxy rubyobj.Foo.this$rubyObject
private static final org.jruby.javasupport.proxy.JavaProxyClass rubyobj.Foo.this$rubyProxyClass
private static final org.jruby.javasupport.Java$JCtorCache rubyobj.Foo.this$rubyCtorCache
private static final org.jruby.Ruby rubyobj.Foo.ruby
private static final org.jruby.RubyClass rubyobj.Foo.rubyClass

This seems to mimic the (working) specs so I must be doing something wrong here. Once I understand what I'm doing wrong, this is ready to merge.

@headius headius added this to the JRuby 9.3.4.0 milestone Mar 22, 2022
Copy link
Member

@headius headius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are approved, but I need an explanation for why my naive example is not working.

@byteit101
Copy link
Member Author

I always run into this too: any usage of the methods that are shared between jrubyc and become_java! for become_java! purposes needs to require jruby/core_ext

irb(main):001:0> class Foo < java.lang.Object; java_field "java.lang.String stringField"; end; f = Foo.new; puts f.class.java_class.declared_fields.to_a
private final org.jruby.java.proxies.ConcreteJavaProxy rubyobj.Foo.this$rubyObject
private static final org.jruby.javasupport.proxy.JavaProxyClass rubyobj.Foo.this$rubyProxyClass
private static final org.jruby.javasupport.Java$JCtorCache rubyobj.Foo.this$rubyCtorCache
private static final org.jruby.Ruby rubyobj.Foo.ruby
private static final org.jruby.RubyClass rubyobj.Foo.rubyClass
=> nil
irb(main):002:0> require 'jruby/core_ext'
=> true
irb(main):003:0> class Foo2 < java.lang.Object; java_field "java.lang.String stringField"; end; f = Foo2.new; puts f.class.java_class.declared_fields.to_a
private final org.jruby.java.proxies.ConcreteJavaProxy rubyobj.Foo2.this$rubyObject
private static final org.jruby.javasupport.proxy.JavaProxyClass rubyobj.Foo2.this$rubyProxyClass
private static final org.jruby.javasupport.Java$JCtorCache rubyobj.Foo2.this$rubyCtorCache
private static final org.jruby.Ruby rubyobj.Foo2.ruby
private static final org.jruby.RubyClass rubyobj.Foo2.rubyClass
public java.lang.String rubyobj.Foo2.stringField
=> nil
irb(main):004:0> 

@headius
Copy link
Member

headius commented Mar 22, 2022

@byteit101 Oh boy, that does fix it. Ok, we should do something better than that in the future, but that's not your bug.

Let's merge this!

@headius headius merged commit 5306465 into jruby:jruby-9.3 Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants