Reflection: how does one access a protected member in a superclass reflectively?

Rony G. Flatscher Rony.Flatscher at wu.ac.at
Thu Jan 18 15:07:09 UTC 2018


Dear Alan:

tried to come up with a "cleaner" version to zip it up, however the error would not occur there.

---

As I have to get off for today, I just zipped up yesterday's version "as is" that exhibits that
compile error and attach it to this e-mail.

Just unzip it, go into "java9module" (this is on Windows):

  * ./ contains the (Windows) batch files and TestUse.java
      o to compile all sources:
          + 1_compile.cmd
      o to compile TestUse.java:
          + 5_compile_and_run_TestUse.cmd
  * src/ contains the sources
  * out/ contains the compiled stuff

If you prefer and can wait until next week, I will try to find out the differences between the
"cleaned" version (removed all Interfaces for that version) and yesterday's version and report back.

---rony


On 17.01.2018 20:43, Alan Bateman wrote:
> 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