# java.lang.IllegalAccessError: class X (in module Y) cannot access class Z (in module W) because module W does not export Z to module Y

- **ID:** `java/illegalaccesserror-module-does-not-export`
- **Domain:** java
- **Category:** module_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

This error occurs in Java 9+ module system when a class from one module tries to reflectively access a class from another module that does not export the package, typically due to missing '--add-exports' or '--add-opens' JVM flags.

## Version Compatibility

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

## Workarounds

1. **Add JVM flags: `--add-opens java.base/java.lang=ALL-UNNAMED` to open the package to all unnamed modules. For example: `java --add-opens java.base/java.lang=ALL-UNNAMED -jar myapp.jar`** (90% success)
   ```
   Add JVM flags: `--add-opens java.base/java.lang=ALL-UNNAMED` to open the package to all unnamed modules. For example: `java --add-opens java.base/java.lang=ALL-UNNAMED -jar myapp.jar`
   ```
2. **Update the module-info.java of your application to add 'requires' and 'exports' directives: `requires java.base; exports com.example.myapp to some.module;`** (85% success)
   ```
   Update the module-info.java of your application to add 'requires' and 'exports' directives: `requires java.base; exports com.example.myapp to some.module;`
   ```
3. **As a temporary workaround, run the application on the classpath (remove module-info.java) to bypass module system restrictions entirely.** (75% success)
   ```
   As a temporary workaround, run the application on the classpath (remove module-info.java) to bypass module system restrictions entirely.
   ```

## Dead Ends

- **Adding the dependency to pom.xml or build.gradle to include the missing module** — The error is not about missing dependencies; it's about module access control. Adding the dependency does not grant reflective access to internal packages. (80% fail)
- **Setting the classpath to include all jars without module declarations** — If the application runs as a named module (e.g., with module-info.java), classpath changes do not override module access restrictions. (70% fail)
- **Recompiling the library with public modifiers on the target class** — The error is about module exports, not Java access modifiers; even public classes in non-exported packages are inaccessible. (90% fail)
