Reflection: how does one access a protected member in a superclass reflectively?
Alan Bateman
Alan.Bateman at oracle.com
Wed Jan 17 19:43:38 UTC 2018
On 17/01/2018 18:53, Rony G. Flatscher wrote:
>
> :
>
>
> Not with Java 9 javac, the following Java program:
>
> public class TestUse
> {
> public static void main (String args[]) {
> mtest3.Class03A o=new mtest3.Class03A();
> System.out.println("o: "+o+", myClassName: "+o.myClassName);
> }
> }
>
> yields the error message:
>
> F:\work\svn\bsf4oorexx\trunk\bsf4oorexx.dev\testUnits\bsf4rexx\java9modules>java
> -cp ".;F:\work\svn\bsf4oorexx\trunk;.;C:\Program Files
> (x86)\BSF4ooRexx\bsf4ooRexx-v600-20180101-bin.jar;C:\Program Files
> (x86)\BSF4ooRexx\jni4net.j-0.8.8.0.jar;C:\Program Files
> (x86)\BSF4ooRexx\oorexx.net.jar;." --module-path out --add-modules
> mod_A,mod_B,mod_C TestUse
> Exception in thread "main" java.lang.IllegalAccessError: tried to
> access field mtest1.Class01A.myClassName from class TestUse
> at TestUse.main(TestUse.java:5)
>
If it compiles then it should run so something isn't right here. I just
tried this with JDK 9 and JDK 10 EA builds but couldn't duplicate it
(the compilation fails as expected because myClassName has protected
access in mod_A/mtest1.Class01A).
Would you mind zipping up the sources for mod_A, mod_B, and mod_C so we
can duplicate this?
-Alan
More information about the jigsaw-dev
mailing list