-
-
Notifications
You must be signed in to change notification settings - Fork 925
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
Unable to use protected java method in jruby with jdk9 #4851
Comments
Get a full trace for me with In order to reduce warnings on Java 9, we now check if a module is open before we try to setAccessible the otherwise-inaccessible methods. That may mean we're binding methods that we can't set accessible, and then they're getting called. That's obviously not ideal, but we can't avoid binding it altogether, especially for these inheritance cases that should have access to the parent class. Long term, we are likely going to need to do more with invokedynamic to properly get access to call those protected methods in parent classes, rather than setting them accessible. But we need a decent workaround now. The full trace will help me sort out where this is happening. We need to start running our Java integration tests on JRuby to see how much breaks with modules. |
To simplify testing I have created a new repo https://github.com/monkstone/protected_method WARNING: An illegal reflective access operation has occurred invokeWithArguments at java/lang/invoke/MethodHandle.java:638 load at org/jruby/ir/Compiler.java:95 runScript at org/jruby/Ruby.java:828 runNormally at org/jruby/Ruby.java:747 runNormally at org/jruby/Ruby.java:765 runFromMain at org/jruby/Ruby.java:578 doRunFromMain at org/jruby/Main.java:417 internalRun at org/jruby/Main.java:305 run at org/jruby/Main.java:232 main at org/jruby/Main.java:204 |
Notes on getting indy to do a better job here:
I have not looked at your repo yet (or processing.org + jruby in a long time). Can you clarify: this is a call you're attempting to make to a protected method in a parent class from a Ruby subclass of that class, right? |
Thats correct, although in a test I found issue exists with a direct call to a protected java method of java class from jruby. |
Yes, those are two different cases though. Your case is more important, since when extending a class you should be able to call its protected methods. The other case is not as important to support, since Java code could not legally make such a call either. |
I am having same issue with activerecord-jdbc-adapter.
Is there any solution ? |
@faisalrabbani there isn't except for downgrading to Java 8 ATM, your case might also be considered slightly more specific. we can fix that at AR-JDBC's end -> that does not fix the issue reported thought |
@faisalrabbani Please report your issue at jruby/activerecord-jdbc-adapter please. This one should be fixable. The issue here is more related to the cases where we can't fix or workaround the protected access. |
For my propane project I have created a custom PApplet class, where I create protected void runSketch() {
runSketch(new String[0]);
} fix
The runSketch with String[] args protected void runSketch(final String[] args) {
final String[] argsWithSketchName = new String[args.length + 1];
System.arraycopy(args, 0, argsWithSketchName, 0, args.length);
final String className = this.getClass().getSimpleName();
final String cleanedClass
= className.replaceAll("__[^_]+__\\$", "").replaceAll("\\$\\d+", "");
argsWithSketchName[args.length] = cleanedClass;
runSketch(argsWithSketchName, this);
} PS: the However this is not possible with JRubyArt which relies on a user installed version of processing Further selected sketches in propane now failing with other inherited |
Is there some way we we could get the Processing folks to expose this logic? I get that it's not a great solution to make these methods public, but protected is a difficult visibility for us to call through. The general problem of not being able to call protected methods will require Java 9 flags (expose/open reflection up for specific classes/modules, or disable checking completely) or a fully invokedynamic-based solution that can properly handle protected calls from an interface implementation in Ruby. |
I can understand your reluctance to create a fix however there is an expectation in java that inherited classes can use protected method, so when a ruby class inherits from a java class there is a similar expectation. So in addition to the one critical case that I can fix with propane there is a problem with our |
Right, I understand that. It's not impossible to support, but with the many levels of method dispatch plumbing it will take some creative use of invokedynamic to do so. I have not had a chance to look at module system changes in Java 10...perhaps they have made it easier to soften these checks? |
As this seems to be jdk9 specific (and therefore transitory) I am closing issue as fixed with jdk10 |
Looks like it still persists with jdk10
Error:
|
@prashantvithani Are you sure this is same issue, I don't recognize your error message as being the same I had. TypeError: illegal access on 'test_method': class org.jruby.javasupport.JavaMethod cannot access a member of class monkstone.ProtectedSuper with modifiers "protected" Further I can confirm my original issue (call to |
as @monkstone noted its not entirely the same, and I would argue that it was uncharted territory before: |
Unable to use inherited, protected method with jdk9.
Environment
Failing Setup:
jruby 9.1.14.0 (2.3.3) 2017-11-08 2176f24 Java HotSpot(TM) 64-Bit Server VM 9.0.1+11 on 9.0.1+11 +jit [linux-x86_64]
Linux tux-PC-2163 4.10.0-38-generic Add quick support for using jruby on MSYS | MinGW #42~16.04.1-Ubuntu SMP Tue Oct 10 16:32:20 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Passing Setup
jruby 9.1.14.0 (2.3.3) 2017-11-08 2176f24 OpenJDK 64-Bit Server VM 25.151-b12 on 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12 +jit [linux-x86_64]
Linux tux-PC-2163 4.10.0-38-generic Add quick support for using jruby on MSYS | MinGW #42~16.04.1-Ubuntu SMP Tue Oct 10 16:32:20 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Expected Behavior
see link https://github.com/monkstone/rbprocessing
Actual Behavior
TypeError
messageThe runSketch method
The
runSketch
method is provided by processing.org, primarily for the benefit ofprocessing.py
, that usesjython
to create a python wrapper around processing. InJRubyArt
andpropane
I have created a ruby wrapper around processing usingjruby
. Is there a way I can still access this method with jdk9?Behaviour since confirmed with simpler java test case, that is also included in repo.
The text was updated successfully, but these errors were encountered: