Home >Java >javaTutorial >What is Illegal Reflective Access in Java 9 and How Can I Fix It?
Illegal Reflective Access in Java 9
Following the introduction of modularity in Java 9, developers have encountered issues related to illegal reflective access. To fully grasp this concept, it's essential to first understand the Module System's "Relaxed-strong-encapsulation."
Definition of Illegal Reflective Access
Illegal reflective access refers to situations where reflective operations are performed in a manner not intended by the modular design principles. It violates the encapsulation barriers established between modules and their packages.
Circumstances Triggering the Warning
The warning for illegal reflective access is triggered when:
Relaxation of Capsule Principles
Java 9 introduced the --illegal-access launcher option with a default setting of permit to aid in migration. In permit mode:
Configuration Modes
The --illegal-access option can be configured with different modes:
How to Identify and Fix
To avoid illegal reflective access, developers can:
Warning Message
Illegal reflective access operations result in warnings with the following format:
WARNING: Illegal reflective access by $PERPETRATOR to $VICTIM
where:
Ensuring Future Compatibility
To ensure future compatibility, it's crucial to eliminate illegal reflective accesses and ensure modules follow proper encapsulation principles.
The above is the detailed content of What is Illegal Reflective Access in Java 9 and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!