Working on a legacy JRuby app (1.6.8) running under Java 11, I traced a peculiar error a test case: "require 'java'; puts java::util::regex::Pattern.class"
errors ArgumentError: wrong number of arguments (0 for 1)
. For other built-in JRE classes, this seems to work fine (see below).
This causes JRuby itself to fail sometimes, at this line in https://github.com/jruby/jruby/blob/1.6.8/lib/ruby/site_ruby/shared/builtin/javasupport/core_ext/object.rb#L10 :
if self.class.superclass.instance_method(:method_added) != method(:java_package_method_added)
To get the app to work, I had to comment out that line in the JRuby source.
I'm perplexed as to the cause of this, or how to fix it appropriately. Google shows several instances of people getting that error when trying to load particular apps, but no one figuring out why (all the solutions said "try different versions of the app).
Why can JRuby not execute .class
? What argument is it expecting?
Complete trace below:
$ java -version
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)
$ ./jruby -v
jruby 1.6.8 (ruby-1.8.7-p357) (2012-09-18 1772b40) (Java HotSpot(TM) 64-Bit Server VM 11.0.1) [linux-amd64-java]
$ ./jruby -e "require 'java'; puts java::util::regex::Matcher.class"
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.jruby.java.invokers.RubyToJavaInvoker to method java.lang.Object.registerNatives()
WARNING: Please consider reporting this to the maintainers of org.jruby.java.invokers.RubyToJavaInvoker
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Class
$ ./jruby -e "require 'java'; puts java::lang::String.class"
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.jruby.java.invokers.RubyToJavaInvoker to method java.lang.Object.registerNatives()
WARNING: Please consider reporting this to the maintainers of org.jruby.java.invokers.RubyToJavaInvoker
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Class
$ ./jruby -e "require 'java'; puts java::util::regex::Pattern.class"
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.jruby.java.invokers.RubyToJavaInvoker to method java.lang.Object.registerNatives()
WARNING: Please consider reporting this to the maintainers of org.jruby.java.invokers.RubyToJavaInvoker
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
ArgumentError: wrong number of arguments (0 for 1)
(root) at -e:1
Java behavior
Java itself seems to have no problem:
jshell> int.class
$6 ==> int
jshell> String.class
$7 ==> class java.lang.String
jshell> Pattern.class
$8 ==> class java.util.regex.Pattern
Partial Solution?
I can fix this error in JRuby by commenting out the if
statement referenced above. However, on this legacy app, JRuby is in a compiled jar, and so I can't edit its source. Is there a way to add a monkey patch to JRuby, without changing the binary jar, to fix the failing if
statement?
Aucun commentaire:
Enregistrer un commentaire