Forum Stats

  • 3,853,806 Users
  • 2,264,277 Discussions


Identifying illegal access from code compiled for earlier versions

Rde1-Oracle Member Posts: 103 Employee
edited Sep 25, 2017 7:57AM in Java SE Early Access

Java 9 EA 181

If I have code which uses an encapsulated API - for example - then I will get an error at compile time with Java 9.  But if have code compiled with Java 8 or earlier, then how to I detect this access at runtime in Java 9?  The --illegal-access = warn or debug modes seem to apply to reflective access only.

For example, this code compiled by Java 8 runs without warnings in Java 9:


I have to use --illegal-access=deny to detect this reference, but that terminates the VM and will prevent other references from being detected.  If this is third-party code I would want to get warnings for all illegal references so I can pass them on to the developer.  I understand that the --illegal-access option is used to control reflective access, so this code:


does generate a warning in Java 9.  But i need warnings for non-reflective use also.