Home >Java >javaTutorial >How to Fix Java 9's InaccessibleObjectException: JDK and Application Code Solutions?
How to Resolve InaccessibleObjectException on Java 9
When using Java 9, developers may encounter the InaccessibleObjectException. It arises due to the Java Platform Module System's implementation of strong encapsulation.
Exception Message Breakdown:
Unable to make {member} accessible: module {A} does not "opens {package}" to {B}
Main Scenarios Causing the Exception:
1. Reflective Call Into JDK
2. Reflection Over Application Code
1. Solution for Reflective Call Into JDK:
Use the following command-line flag to open the specified package for reflection:
java --add-opens java.base/java.lang=ALL-UNNAMED
Replace ALL-UNNAMED with the name of the named module if applicable.
2. Solution for Reflection Over Application Code:
Edit module {A} to open the internal package using one of the following options within its module descriptor:
The above is the detailed content of How to Fix Java 9's InaccessibleObjectException: JDK and Application Code Solutions?. For more information, please follow other related articles on the PHP Chinese website!