Skip to content

Java::JavaLang::NoClassDefFoundError (java/sql/Date) #6608

@fzakaria

Description

@fzakaria

Environment Information

Provide at least:

  • JRuby version: 9.2.13.0 & 9.2.16.0
Picked up JAVA_TOOL_OPTIONS: -Djava.library.path=/nix/store/9l06v7fc38c1x3r2iydl15ksgz0ysb82-glibc-2.32/lib
jruby 9.2.13.0 (2.5.7) 2020-08-03 9a89c94bcc OpenJDK 64-Bit Server VM 11.0.9+0-adhoc..source on 11.0.9+0-adhoc..source +jit [linux-x86_64]
  • Operating system and platform: Linux fmzakari-glaptop 5.7.17-1rodete5-amd64 #1 SMP Debian 5.7.17-1rodete5 (2021-01-08) x86_64 GNU/Linux

Expected Behavior

Attempting to call to_java on a RubyTime object and have it return a java.sql.Date object returns NoClassDefFoundError.

What is perculiar is that I can clearly create a java.sql.Date, so it seems to be accessible via my classpath.

Here is a minimal reproduction with irb:

# let us prove first that java.sql.Date works!
irb(main):013:0> date = java.sql.Date.new(0)
=> #<Java::JavaSql::Date:0x2715644a>

# now fetch the class
irb(main):014:0> clazz = java.sql.Date.java_class
=> class java.sql.Date

# lets create a RubyTime object now
irb(main):015:0> t = Time.new(0)
=> 0000-01-01 00:00:00 -0752

# lets try to cast it to java.sql.Date
irb(main):016:0> t.to_java(clazz)
Traceback (most recent call last):
       16: from org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:361)
       15: from org.jruby.ir.instructions.CallBase.interpret(CallBase.java:549)
       14: from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:84)
       13: from org.jruby.RubyKernel$INVOKER$s$0$3$eval.call(RubyKernel$INVOKER$s$0$3$eval.gen)
       12: from org.jruby.RubyKernel.eval(RubyKernel.java:1048)
       11: from org.jruby.RubyKernel.evalCommon(RubyKernel.java:1086)
       10: from org.jruby.ir.interpreter.Interpreter.evalWithBinding(Interpreter.java:182)
        9: from org.jruby.ir.interpreter.Interpreter.evalCommon(Interpreter.java:158)
        8: from org.jruby.ir.interpreter.Interpreter.INTERPRET_EVAL(Interpreter.java:106)
        7: from org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:72)
        6: from org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:316)
        5: from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:174)
        4: from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:375)
        3: from org.jruby.java.addons.KernelJavaAddons$INVOKER$s$to_java.call(KernelJavaAddons$INVOKER$s$to_java.gen)
        2: from org.jruby.java.addons.KernelJavaAddons.to_java(KernelJavaAddons.java:29)
        1: from org.jruby.RubyTime.toJava(RubyTime.java:1472)
Java::JavaLang::NoClassDefFoundError (java/sql/Date)

A bit of a headscratcher for me since right before the call to to_java, you can see it working.

Actual Behavior

I expect the cast to work.
If I change the JDK we are using to JDK8, I see that the results work as intended.

irb(main):001:0> clazz = java.sql.Date.java_class
=> class java.sql.Date
irb(main):002:0>  t = Time.new(0)
=> 0000-01-01 00:00:00 -0752
irb(main):003:0> t.to_java(clazz)
=> #<Java::JavaSql::Date:0x5223e5ee>

There is something funky here going on with module-loading.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions