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

Can't call methods of private subclasses in a module #5894

Open
yamam opened this issue Sep 27, 2019 · 1 comment

Comments

@yamam
Copy link

commented Sep 27, 2019

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)
@headius

This comment has been minimized.

Copy link
Member

commented Sep 27, 2019

Thank you for the complete repro...I'll have a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.