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 class fails to load #1972

Closed
bastik opened this issue Sep 14, 2014 · 8 comments
Closed

Java class fails to load #1972

bastik opened this issue Sep 14, 2014 · 8 comments

Comments

@bastik
Copy link

bastik commented Sep 14, 2014

Trying to load a Java class from jruby results in an error.

Script:

require 'java'
require 'josm-snapshot-7480.jar'
op = org.openstreetmap.josm.data.osm.OsmPrimitive

Error:

NameError: missing class or uppercase package name (`org.openstreetmap.josm.data.osm.OsmPrimitive'), caused by (NameError) cannot initialize Java class org.openstreetmap.josm.data.osm.OsmPrimitive
  get_proxy_or_package_under_package at org/jruby/javasupport/JavaUtilities.java:54
                      method_missing at file:/home/username/Downloads/bin/jruby-1.7.15/lib/jruby.jar!/jruby/java/java_package_module_template.rb:14
                              (root) at test.rb:5

Observations:

  • No error for other classes that I've tried so far, even in the same package
  • subclasses of OsmPrimitive are also affected
  • superclasses of OsmPrimitive work fine

How to reproduce:

Environment:

  • jruby 1.7.15 (1.9.3p392) 2014-09-03 82b5cc3 on OpenJDK 64-Bit Server VM 1.7.0_65-b32 +jit [linux-amd64]
@kares
Copy link
Member

kares commented Apr 9, 2016

its probably missing a .jar dependency - which should be reported better in latest 1.7.x
... unable to test this out since the josm-snapshot.jar is no longer accessible.

@kares kares closed this as completed Apr 9, 2016
@kares kares added this to the Invalid or Duplicate milestone Apr 9, 2016
@bastik
Copy link
Author

bastik commented Apr 10, 2016

Thanks for your response!

I don't think it is a .jar dependency as the linked jar file is a standalone release. I can still reproduce the problem with current versions:

Script:

require 'java'
require 'josm-snapshot-10130.jar'
op = org.openstreetmap.josm.data.osm.OsmPrimitive

Error:

ameError: cannot initialize Java class org.openstreetmap.josm.data.osm.OsmPrimitive
  get_proxy_or_package_under_package at org/jruby/javasupport/JavaUtilities.java:54
                      method_missing at file:/usr/share/java/jruby-core-1.7.21.jar!/jruby/java/java_package_module_template.rb:14
                              (root) at testruby.rb:4

Jar file download: https://josm.openstreetmap.de/download/josm-snapshot-10130.jar

Environment:

  • jruby 1.7.21 (1.9.3p551) 2015-09-15 fffffff on OpenJDK 64-Bit Server VM 1.8.0_66-internal-b17 +jit [linux-amd64]

@kares
Copy link
Member

kares commented Apr 11, 2016

OK, thanks for the feedback - was able to reproduce this time.

@kares kares reopened this Apr 11, 2016
@kares kares removed this from the Invalid or Duplicate milestone Apr 11, 2016
@kares
Copy link
Member

kares commented Apr 11, 2016

still the cause seems to be the .jar itself (NPE) and seems to have nothing to do with JRuby :

java.lang.ExceptionInInitializerError
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.jruby.javasupport.JavaSupportImpl.loadJavaClass(JavaSupportImpl.java:156)
    at org.jruby.javasupport.Java.getProxyClassOrNull(Java.java:836)
    at org.jruby.javasupport.Java.getProxyClassOrNull(Java.java:823)
    at org.jruby.javasupport.Java.getProxyOrPackageUnderPackage(Java.java:781)
    at org.jruby.javasupport.JavaPackage.method_missing(JavaPackage.java:261)
    at org.jruby.javasupport.JavaPackage$INVOKER$i$method_missing.call(JavaPackage$INVOKER$i$method_missing.gen)
    at org.jruby.internal.runtime.methods.JavaMethod$JavaMethodN.call(JavaMethod.java:738)
    at org.jruby.runtime.Helpers$MethodMissingMethod.call(Helpers.java:352)
    at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:193)
    at org.jruby.runtime.callsite.CachingCallSite.callMethodMissing(CachingCallSite.java:380)
    at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:290)
    at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:131)
    at josm.invokeOther9:OsmPrimitive(josm.rb)
    at josm.RUBY$script(josm.rb:4)
    at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
    at org.jruby.ir.Compiler$1.load(Compiler.java:111)
    at org.jruby.Ruby.runScript(Ruby.java:825)
    at org.jruby.Ruby.runScript(Ruby.java:817)
    at org.jruby.Ruby.runNormally(Ruby.java:755)
    at org.jruby.Ruby.runFromMain(Ruby.java:576)
    at org.jruby.Main.doRunFromMain(Main.java:425)
    at org.jruby.Main.internalRun(Main.java:310)
    at org.jruby.Main.run(Main.java:239)
    at org.jruby.Main.main(Main.java:201)
Caused by: java.lang.NullPointerException
    at org.openstreetmap.josm.data.osm.OsmPrimitive.compileDirectionKeys(OsmPrimitive.java:875)
    at org.openstreetmap.josm.data.osm.OsmPrimitive.<clinit>(OsmPrimitive.java:869)
    ... 26 more

@mkristian
Copy link
Member

converting the ruby script into a java class words :(

but

require './josm-snapshot-10130.jar'
org.openstreetmap.josm.Main.initApplicationPreferences
op = org.openstreetmap.josm.data.osm.OsmPrimitive

also works with jruby. not sure where this extra method is called when running java and why we miss it in JRuby

@bastik
Copy link
Author

bastik commented Apr 11, 2016

kares: You are right, it is a NPE in the Java code. It works with proper intialization. Sorry for the noise, the error message was misleading me, especially the "method_missing" bit. Given the stack trace you posted, I would have figured it out.

mkristian: Cannot reproduce, I get the same error in Java code (changing abstract class OsmPrimitive to subclass Node):

    public static void main(String[] args) {
        Node n = new Node();
    }

error:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at org.openstreetmap.josm.JosmTest.main(JosmTest.java:67)
Caused by: java.lang.NullPointerException
    at org.openstreetmap.josm.data.osm.OsmPrimitive.compileDirectionKeys(OsmPrimitive.java:875)
    at org.openstreetmap.josm.data.osm.OsmPrimitive.<clinit>(OsmPrimitive.java:869)
    ... 1 more

@bastik bastik closed this as completed Apr 11, 2016
@mkristian
Copy link
Member

@bastik right, maybe my java class did not run the <clinit> bits.

@kares
Copy link
Member

kares commented Apr 11, 2016

@bastik yes the cause in this case got hidden - generally adding jruby -d or -w usually helps (altough in this case it seems it only helps on JRuby 9K).
seems something spooky about the .jar initialization - you guys should make sure it loads properly. adding it to a -cp and doing: Class.forName("org.openstreetmap.josm.data.osm.OsmPrimitive") should reproduce.

@kares kares added this to the Invalid or Duplicate milestone 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