Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Identifying illegal access from code compiled for earlier versions

Rde1-OracleSep 8 2017 — edited Sep 25 2017

Java 9 EA 181

If I have code which uses an encapsulated API - for example sun.security.x509.X500Name - 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:

System.out.println(new sun.security.x509.X500Name("cn=abc"));

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:

System.out.println(Class.forName("sun.security.x509.X500Name").getConstructor(String.class).newInstance("cn=abc"));

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

Comments
Post Details
Added on Sep 8 2017
2 comments
677 views