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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

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

User,

Always mention your JDev version.

I would first start from here : Testing and Debugging ADF Components

-Arun

Timo Hahn
Answer

One reason might be that a stand alone server normally has different logging level then you embedded server.

Next thing I'd that you should avoid using system out printing to log messages. Such messages can't be turned off and fill up the server log, and only this,as they are printed to system out.

Instead you should implement ADF logging. A very good article, which has multiple parts, can be found at https://blogs.oracle.com/groundside/entry/adventures_in_adf_logging_part

Timo

Marked as Answer by Salman5 · Sep 27 2020
1 - 2

Post Details

Added on Sep 8 2017
2 comments
575 views