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

java_field causes NPE when using derived class of a java object #4165

Closed
byteit101 opened this issue Sep 21, 2016 · 2 comments
Closed

java_field causes NPE when using derived class of a java object #4165

byteit101 opened this issue Sep 21, 2016 · 2 comments

Comments

@byteit101
Copy link
Member

Environment

  • jruby 9.1.5.0 (2.3.1) 2016-09-07 036ce39 Java HotSpot(TM) 64-Bit Server VM 25.101-b13 on 1.8.0_101-b13 +jit [linux-x86_64]

Test Case

require 'jruby/core_ext'
class A < Java::javafx::scene::layout::BorderPane
  java_field "java.lang.Object label"
end
A.become_java!

I would expect this to succeed, as it does if you swap the parent with a ruby class

Unexpected Error

Unhandled Java exception: java.lang.NullPointerException
java.lang.NullPointerException: null
      generateFieldAccessors at org/jruby/java/addons/ClassJavaAddons.java:77
                  becomeJava at org/jruby/java/addons/ClassJavaAddons.java:69
                 become_java at org/jruby/java/addons/ClassJavaAddons.java:40
                        call at org/jruby/java/addons/ClassJavaAddons$INVOKER$s$become_java.gen:-1
                cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:318
                        call at org/jruby/runtime/callsite/CachingCallSite.java:131
  invokeOther16:become_java! at jrubyfx-fxmlloader2.rb:4
                      <main> at jrubyfx-fxmlloader2.rb:4
         invokeWithArguments at java/lang/invoke/MethodHandle.java:627
                        load at org/jruby/ir/Compiler.java:111
                   runScript at org/jruby/Ruby.java:834
                 runNormally at org/jruby/Ruby.java:749
                 runNormally at org/jruby/Ruby.java:767
                 runFromMain at org/jruby/Ruby.java:580
               doRunFromMain at org/jruby/Main.java:425
                 internalRun at org/jruby/Main.java:313
                         run at org/jruby/Main.java:242
                        main at org/jruby/Main.java:204
@headius
Copy link
Member

headius commented Sep 21, 2016

Looks like this could happen if the class is not reifiable; reifyWithAncestors will not set a reified class, and the later getReifiedClass will just return null. So the logic is not robust in the presence of unreifiable classes (bug 1) and for whatever reason this simple class is showing up as unreifiable (bug 2).

@headius
Copy link
Member

headius commented Sep 21, 2016

Ok, I missed a detail in your example: you're extending a concrete Java class. become_java! and concrete extension have never been wired up together, so I'm not at all surprised that this failed.

A Ruby subclass of a concrete Java class is already basically a become_java! class, so perhaps the right approach would be for us to make concrete subclassing aware of java_field and java_signature and so on. However, the code that does concrete extension is a bit of an abyss...none of us really understand all of it.

@kares What do you think?

@byteit101 I will at least add an more appropriate error to become_java! for non-reifiable cases.

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