Forum Stats

  • 3,853,806 Users
  • 2,264,277 Discussions
  • 7,905,450 Comments

Discussions

Identifying illegal access from code compiled for earlier versions

Rde1-Oracle
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 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.

Answers