{
  "id": "java/illegalaccesserror-module-does-not-export",
  "signature": "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",
  "signature_zh": "java.lang.IllegalAccessError：类X（在模块Y中）无法访问类Z（在模块W中），因为模块W未将Z导出到模块Y",
  "regex": "java\\.lang\\.IllegalAccessError: class \\S+ \\(in module \\S+\\) cannot access class \\S+ \\(in module \\S+\\) because module \\S+ does not export \\S+ to module \\S+",
  "domain": "java",
  "category": "module_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "在Java 9+模块系统中发生，当一个模块中的类尝试通过反射访问另一个模块中的类，而目标模块未导出该包时，通常由于缺少'--add-exports'或'--add-opens' JVM标志。",
  "versions": [
    {
      "version": "Java 9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Java 11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Java 17",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Java 21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "OpenJDK 11.0.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding the dependency to pom.xml or build.gradle to include the missing module",
      "why_fails": "The error is not about missing dependencies; it's about module access control. Adding the dependency does not grant reflective access to internal packages.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Setting the classpath to include all jars without module declarations",
      "why_fails": "If the application runs as a named module (e.g., with module-info.java), classpath changes do not override module access restrictions.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Recompiling the library with public modifiers on the target class",
      "why_fails": "The error is about module exports, not Java access modifiers; even public classes in non-exported packages are inaccessible.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "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`",
      "success_rate": 0.9,
      "how": "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`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Update the module-info.java of your application to add 'requires' and 'exports' directives: `requires java.base; exports com.example.myapp to some.module;`",
      "success_rate": 0.85,
      "how": "Update the module-info.java of your application to add 'requires' and 'exports' directives: `requires java.base; exports com.example.myapp to some.module;`",
      "condition": "",
      "sources": []
    },
    {
      "action": "As a temporary workaround, run the application on the classpath (remove module-info.java) to bypass module system restrictions entirely.",
      "success_rate": 0.75,
      "how": "As a temporary workaround, run the application on the classpath (remove module-info.java) to bypass module system restrictions entirely.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "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`",
    "Update the module-info.java of your application to add 'requires' and 'exports' directives: `requires java.base; exports com.example.myapp to some.module;`",
    "As a temporary workaround, run the application on the classpath (remove module-info.java) to bypass module system restrictions entirely."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/IllegalAccessError.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-09-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}