Skip to content

NativeDate::getJSTimeValue call fails in jruby 9.2 #42

@cataphract

Description

@cataphract

This call to getJSTimeValue fails in jruby-9.2:

module Rhino
  module To

    def to_ruby(object)
      case object
      # ...
      when JS::NativeDate        then Time.at(object.getJSTimeValue / 1000)
$ jruby --version
jruby 9.1.17.0 (2.3.3) 2018-04-20 d8b1ff9 OpenJDK 64-Bit Server VM 25.252-b09 on 1.8.0_252-8u252-b09-1~18.04-b09 +jit [linux-x86_64]
$ jruby -e 'require "rhino"; p eval_js "new Date()"'
2020-04-27 16:10:20 +0100
$ jruby -e 'require "rhino"; p Gem.loaded_specs["therubyrhino"].version'
#
$ rvm use jruby-9.2
Using /home/glopes/.rvm/gems/jruby-9.2.11.1
$ jruby --version
jruby 9.2.11.1 (2.5.7) 2020-03-25 b1f55b1a40 OpenJDK 64-Bit Server VM 25.252-b09 on 1.8.0_252-8u252-b09-1~18.04-b09 +jit [linux-x86_64]
$ jruby -e 'require "rhino"; p eval_js "new Date()"'
NoMethodError: undefined method `getJSTimeValue' for org.mozilla.javascript.NativeDate@27ce24aa:Java::OrgMozillaJavascript::NativeDate
Did you mean?  get_associated_value
  method_missing at org/jruby/RubyBasicObject.java:1708
  method_missing at /home/glopes/.rvm/gems/jruby-9.2.11.1/gems/therubyrhino-2.1.2/lib/rhino/rhino_ext.rb:122
         to_ruby at /home/glopes/.rvm/gems/jruby-9.2.11.1/gems/therubyrhino-2.1.2/lib/rhino/wormhole.rb:10
            eval at /home/glopes/.rvm/gems/jruby-9.2.11.1/gems/therubyrhino-2.1.2/lib/rhino/context.rb:146
         do_open at /home/glopes/.rvm/gems/jruby-9.2.11.1/gems/therubyrhino-2.1.2/lib/rhino/context.rb:267
            open at /home/glopes/.rvm/gems/jruby-9.2.11.1/gems/therubyrhino-2.1.2/lib/rhino/context.rb:252
            eval at /home/glopes/.rvm/gems/jruby-9.2.11.1/gems/therubyrhino-2.1.2/lib/rhino/context.rb:140
         eval_js at /home/glopes/.rvm/gems/jruby-9.2.11.1/gems/therubyrhino-2.1.2/lib/rhino/object.rb:13
         do_open at /home/glopes/.rvm/gems/jruby-9.2.11.1/gems/therubyrhino-2.1.2/lib/rhino/context.rb:267
            open at /home/glopes/.rvm/gems/jruby-9.2.11.1/gems/therubyrhino-2.1.2/lib/rhino/context.rb:252
            open at /home/glopes/.rvm/gems/jruby-9.2.11.1/gems/therubyrhino-2.1.2/lib/rhino/context.rb:43
         eval_js at /home/glopes/.rvm/gems/jruby-9.2.11.1/gems/therubyrhino-2.1.2/lib/rhino/object.rb:12
           at -e:1
$ jruby -e 'require "rhino"; p Gem.loaded_specs["therubyrhino"].version'
#

The result is similar to that described in #27, but I checked with lsof and object.java_class.class_loader.getURLs.to_a that the loaded rhino jar file was the correct one (/home/glopes/.rvm/gems/jruby-9.2.11.1/gems/therubyrhino_jar-1.7.8/jar/rhino-1.7.8.jar)

This seems related to a change in how jruby handles access to package-protected methods. For instance, with

Pkg/MyClass.java

package Pkg;

class MyClass {
    private double val = 42.0;

    public MyClass() {}

    double getVal() { return this.val; }
}

and

require 'java'

$CLASSPATH << __dir__

module J
  include_package 'Pkg'
end

obj = J::MyClass.new
p obj.getVal

This yields

NoMethodError: undefined method `getVal' for #<Java::Pkg::MyClass:0x543c6f6d>
Did you mean?  eval
  <main> at script.rb:10

in 9.2 and the result 42.0 in 9.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions