# WARNING: An illegal reflective access operation has occurred

- **ID:** `java/illegal-reflective-access-warning`
- **Domain:** java
- **Category:** module_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Code is using reflection to access a member of a class in a module that does not export the package to the caller, which is disallowed by the Java module system (JPMS) since Java 9.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Java 9 | active | — | — |
| Java 11 | active | — | — |
| Java 17 | active | — | — |
| Java 21 | active | — | — |

## Workarounds

1. **Add JVM args to open the specific package: `--add-opens java.base/java.lang=ALL-UNNAMED` (replace package and module as needed).** (90% success)
   ```
   Add JVM args to open the specific package: `--add-opens java.base/java.lang=ALL-UNNAMED` (replace package and module as needed).
   ```
2. **Update the library to a version that uses proper module exports or uses `ModuleLayer` API to access non-exported packages.** (85% success)
   ```
   Update the library to a version that uses proper module exports or uses `ModuleLayer` API to access non-exported packages.
   ```
3. **If you control the library, add `exports` directive in `module-info.java` to export the package to the caller module.** (95% success)
   ```
   If you control the library, add `exports` directive in `module-info.java` to export the package to the caller module.
   ```

## Dead Ends

- **Add `--illegal-access=permit` JVM flag to allow all reflective access.** — The `--illegal-access=permit` flag was removed in Java 17; it only works in Java 9-16. In Java 17+, it causes an error: 'Java.lang.IllegalArgumentException: IllegalAccessError'. (95% fail)
- **Set `AccessibleObject.setAccessible(true)` to bypass the warning.** — The warning is generated by the JVM's reflective access check; setAccessible does not suppress the warning or fix the underlying module access issue. (80% fail)
- **Ignore the warning; it's just a warning.** — In future Java versions, illegal reflective access will throw an `InaccessibleObjectException` at runtime, breaking the application. (70% fail)
