{
  "id": "java/illegal-reflective-access-warning",
  "signature": "WARNING: An illegal reflective access operation has occurred",
  "signature_zh": "警告：发生了非法的反射访问操作",
  "regex": "WARNING: An illegal reflective access operation has occurred",
  "domain": "java",
  "category": "module_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "代码使用反射访问某个模块中类的成员，但该模块未将包导出给调用者，自 Java 9 起，Java 模块系统（JPMS）禁止此操作。",
  "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"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Add `--illegal-access=permit` JVM flag to allow all reflective access.",
      "why_fails": "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'.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "Set `AccessibleObject.setAccessible(true)` to bypass the warning.",
      "why_fails": "The warning is generated by the JVM's reflective access check; setAccessible does not suppress the warning or fix the underlying module access issue.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Ignore the warning; it's just a warning.",
      "why_fails": "In future Java versions, illegal reflective access will throw an `InaccessibleObjectException` at runtime, breaking the application.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Add JVM args to open the specific package: `--add-opens java.base/java.lang=ALL-UNNAMED` (replace package and module as needed).",
      "success_rate": 0.9,
      "how": "Add JVM args to open the specific package: `--add-opens java.base/java.lang=ALL-UNNAMED` (replace package and module as needed).",
      "condition": "",
      "sources": []
    },
    {
      "action": "Update the library to a version that uses proper module exports or uses `ModuleLayer` API to access non-exported packages.",
      "success_rate": 0.85,
      "how": "Update the library to a version that uses proper module exports or uses `ModuleLayer` API to access non-exported packages.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If you control the library, add `exports` directive in `module-info.java` to export the package to the caller module.",
      "success_rate": 0.95,
      "how": "If you control the library, add `exports` directive in `module-info.java` to export the package to the caller module.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "添加 JVM 参数以打开特定包：`--add-opens java.base/java.lang=ALL-UNNAMED`（根据需要替换模块和包）。",
    "将库更新到使用正确模块导出或使用 `ModuleLayer` API 访问非导出包的版本。",
    "如果你控制库，在 `module-info.java` 中添加 `exports` 指令，将包导出给调用者模块。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.oracle.com/en/java/javase/17/migrate/migration-guide.pdf",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.8,
  "resolvable": "partial",
  "first_seen": "2023-07-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}