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

Can't access java member variables #5684

Closed
yamam opened this issue Apr 9, 2019 · 7 comments
Closed

Can't access java member variables #5684

yamam opened this issue Apr 9, 2019 · 7 comments
Milestone

Comments

@yamam
Copy link

@yamam yamam commented Apr 9, 2019

Environment

jruby 9.2.7.0 (2.5.3) 2019-04-09 8a269e3 Java HotSpot(TM) 64-Bit Server VM 25.201-b09 on 1.8.0_201-b09 +jit [mswin32-x86_64]

Expected Behavior

JavaTest.java

public class JavaTest {
    public int x;
    public static int y;
}

test.rb

java_import 'JavaTest'

begin
    p JavaTest.new.x
rescue
    p $!
end

begin
    p JavaTest.y
rescue
    p $!
end

You can access java member variables on jruby 9.2.6.0

$ jruby-9.2.6.0/bin/jruby test.rb
0
0

Actual Behavior

You can't access java member variables on jruby 9.2.7.0

$ jruby-9.2.7.0/bin/jruby test.rb
#<NoMethodError: undefined method `x' for #<Java::Default::JavaTest:0x3d45bd>>
#<NoMethodError: undefined method `y' for Java::Default::JavaTest:Class>
@headius headius added this to the JRuby 9.2.8.0 milestone Apr 10, 2019
@headius
Copy link
Member

@headius headius commented Apr 10, 2019

Hmm, did something changes with how we bind fields, @kares?

Loading

@kares
Copy link
Member

@kares kares commented Apr 11, 2019

no changes there, starting to think this might relate to how the default package works (in terms of lookup)
bin/jruby -e "p org.jruby.util.ByteList.new.begin" ... works fine on current master

Loading

@kares
Copy link
Member

@kares kares commented Apr 11, 2019

confirmed, only classes in the default package seem to be problematic, this is Java 8 thus no modules ...

Loading

@kares
Copy link
Member

@kares kares commented Apr 11, 2019

problem seems to be the modulator check from 7f20635#diff-c00f12e0a2700d71b3ad1b39305d8f2bR21 (likely due return false for when it does not need to set). seems to me the condition logic has a typo - should have been || instead of && ... will shoot up a PR with a test to see what CI thinks.

Loading

kares added a commit to kares/jruby that referenced this issue Apr 11, 2019
@kares
Copy link
Member

@kares kares commented Apr 11, 2019

so the problem is klass.getPackage().getName() on Java 8 for default package this is a NPE
since the module system getPackage() returns an (unnamed) package object: headius/backport9#1

Loading

@headius
Copy link
Member

@headius headius commented Apr 11, 2019

backport9 v1.3 has been released and I've pushed update_backport9 branch for JRuby. When that's green I'll merge to master and let you take it from there @kares. I had some odd spec:ji failures locally that may mean my environment is dirty.

Loading

@headius
Copy link
Member

@headius headius commented Apr 11, 2019

@kares #5689 has been merged to master. Your tests look fine, so if that's green go ahead with it.

Loading

@headius headius closed this Apr 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants