. Advertisement .
..3..
. Advertisement .
..4..
What is “warning: an illegal reflective access operation has occurred” ? I am learning about it. Can someone share with me your knowledge and experience?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The cause:
The crux of this problem lies in the Module System#Relaxed-strong-encapsulation.
To support the migration to Java-9, the encapsulation of modules can be loosened. This loosening of encapsulation is controlled at runtime by a new launcher option
--illegal-access
. And the warning is caused in the first reflective-access operation to any such package, but after that point, their is no warnings. This only warning describes the way opening the other warnings and it cannot be avoided.Solution:
To solve this problem, please do the following suggestions:
Run it with –illegal-access=deny and don’t open module packages from one to another without declaration such as a directive(opens) or obvious using of –add-opens VM arg. You could identify static references from compiled code to JDK-internal APIs by using the jdeps tool with the –jdk-internals option.
Remember: You have to ensure your modules don’t make those illegal reflective accesses in order not to face such warnings.
An Oracle article that I found about Java 9 module system is available.
As pointed out in https://ittutoria.net/a/50251958/134894, the differences between the
AccessibleObject#setAccessible
for JDK8 and JDK9 are instructive. JDK9 was specifically addedThis highlights the importance of modules and their exports in Java 9