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

NativeDate::getJSTimeValue call fails in jruby 9.2 #42

Open
cataphract opened this issue Apr 27, 2020 · 2 comments
Open

NativeDate::getJSTimeValue call fails in jruby 9.2 #42

cataphract opened this issue Apr 27, 2020 · 2 comments

Comments

@cataphract
Copy link

cataphract commented Apr 27, 2020

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

@kares
Copy link
Collaborator

kares commented May 1, 2020

in general this is problematic - we'll eventually run into Java enforcing access restrictions since Java 9
so JRuby changed to reflect and only bind public or accessible methods. since Rhino's NativeDate is (package) internal class + the method is only package accessible, this is going to be problematic.

@kares
Copy link
Collaborator

kares commented May 1, 2020

there's an alternate API for doing the conversion Context.jsToJava if you're into experimenting ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants