-
-
Notifications
You must be signed in to change notification settings - Fork 933
Closed
Milestone
Description
Fixed an issue in #5841 where private subclasses could not be accessed.
However, the error still occurs if the class belongs to a module.
Environment
$ java --version
openjdk 11.0.4 2019-07-16
OpenJDK Runtime Environment (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3)
OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3, mixed mode, sharing)
jruby-complete-9.2.9.0-20190926.210253-53.jar
JavaTest.java
package test;
public class JavaTest {
public interface PublicInterface {
public void publicMethod(Integer a);
public void publicMethod(Long a);
}
public PublicInterface publicMember = new PrivateSubclass();
private class PrivateSubclass implements PublicInterface {
public void publicMethod(Integer a) {System.out.println("PrivateSubclass.publicMethod(Integer)");}
public void publicMethod(Long a) {System.out.println("PrivateSubclass.publicMethod(Long)");}
}
}module-info.java
module test {
exports test;
}JavaMain.java
import test.JavaTest;
import org.jruby.embed.ScriptingContainer;
public class JavaMain {
public static void main(String[] args) {
new JavaTest().publicMember.publicMethod(1);
new ScriptingContainer().runScriptlet("java_import 'test.JavaTest'; JavaTest.new.publicMember.publicMethod(1)");
new ScriptingContainer().runScriptlet("java_import 'test.JavaTest'; JavaTest.new.publicMember.java_method(:publicMethod, [java.lang.Integer.java_class]).call(1)");
}
}Expected Behavior
$ javac -d mods/test module-info.java JavaTest.java
$ javac --module-path mods --add-modules test -cp jruby-complete.jar JavaMain.java
$ java --module-path mods --add-modules test -cp .:jruby-complete.jar JavaMain
PrivateSubclass.publicMethod(Integer)
PrivateSubclass.publicMethod(Long)
PrivateSubclass.publicMethod(Integer)
Actual Behavior
$ javac -d mods/test module-info.java JavaTest.java
$ javac --module-path mods --add-modules test -cp jruby-complete.jar JavaMain.java
$ java --module-path mods --add-modules test -cp .:jruby-complete.jar JavaMain
PrivateSubclass.publicMethod(Integer)
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.headius.backport9.modules.Modules (jruby-complete.jar) to method sun.nio.ch.NativeThread.signal(long)
WARNING: Please consider reporting this to the maintainers of com.headius.backport9.modules.Modules
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
TypeError: illegal access on 'publicMethod': class org.jruby.javasupport.JavaMethod cannot access a member of class test.JavaTest$PrivateSubclass (in module test) with modifiers "public"
<main> at <script>:1
Exception in thread "main" org.jruby.embed.EvalFailedException: (TypeError) illegal access on 'publicMethod': class org.jruby.javasupport.JavaMethod cannot access a member of class test.JavaTest$PrivateSubclass (in module test) with modifiers "public"
at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:131)
at org.jruby.embed.ScriptingContainer.runUnit(ScriptingContainer.java:1295)
at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1288)
at JavaMain.main(JavaMain.java:7)
Caused by: org.jruby.exceptions.TypeError: (TypeError) illegal access on 'publicMethod': class org.jruby.javasupport.JavaMethod cannot access a member of class test.JavaTest$PrivateSubclass (in module test) with modifiers "public"
at RUBY.<main>(<script>:1)
Metadata
Metadata
Assignees
Labels
No labels