{
  "id": "java/illegal-format-conversion",
  "signature": "java.util.IllegalFormatConversionException: d != java.lang.String",
  "signature_zh": "java.util.IllegalFormatConversionException：d != java.lang.String",
  "regex": "java\\.util\\.IllegalFormatConversionException: .* != .*",
  "domain": "java",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A format specifier (e.g., %d for integer) is used with an argument of an incompatible type (e.g., String), causing a runtime exception when formatting strings via String.format or PrintStream.printf.",
  "root_cause_type": "generic",
  "root_cause_zh": "格式说明符（例如用于整数的 %d）与不兼容类型的参数（例如 String）一起使用，导致通过 String.format 或 PrintStream.printf 格式化字符串时发生运行时异常。",
  "versions": [
    {
      "version": "Java 8",
      "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": "Change the format specifier to %s to accept any type.",
      "why_fails": "While %s works for strings, it produces the string representation of the object, which may not match the desired numeric formatting (e.g., padding, precision). This changes the output format unintentionally.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Use `String.valueOf(arg)` to convert the argument before formatting.",
      "why_fails": "If the argument is not a string, String.valueOf will still produce a string, but the format specifier %d will still expect an integer, causing the same exception.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Catch the exception and retry with a different format.",
      "why_fails": "This only masks the error; the underlying type mismatch remains and may cause further issues in downstream logic.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure the argument type matches the format specifier. For %d, pass an integer: `String.format(\"Value: %d\", 42)` instead of `String.format(\"Value: %d\", \"42\")`. Convert strings to integers using Integer.parseInt() if necessary.",
      "success_rate": 0.95,
      "how": "Ensure the argument type matches the format specifier. For %d, pass an integer: `String.format(\"Value: %d\", 42)` instead of `String.format(\"Value: %d\", \"42\")`. Convert strings to integers using Integer.parseInt() if necessary.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use the correct format specifier for the argument type: %s for strings, %f for floats, %d for integers. Example: `String.format(\"Name: %s, Age: %d\", name, age)`",
      "success_rate": 0.95,
      "how": "Use the correct format specifier for the argument type: %s for strings, %f for floats, %d for integers. Example: `String.format(\"Name: %s, Age: %d\", name, age)`",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the argument can be of multiple types, use a conditional to apply the correct format specifier: `String.format(arg instanceof Integer ? \"%d\" : \"%s\", arg)`",
      "success_rate": 0.85,
      "how": "If the argument can be of multiple types, use a conditional to apply the correct format specifier: `String.format(arg instanceof Integer ? \"%d\" : \"%s\", arg)`",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "确保参数类型与格式说明符匹配。对于 %d，传递整数：`String.format(\"Value: %d\", 42)` 而不是 `String.format(\"Value: %d\", \"42\")`。如有必要，使用 Integer.parseInt() 将字符串转换为整数。",
    "为参数类型使用正确的格式说明符：字符串用 %s，浮点数用 %f，整数用 %d。示例：`String.format(\"Name: %s, Age: %d\", name, age)`",
    "如果参数可以是多种类型，使用条件语句应用正确的格式说明符：`String.format(arg instanceof Integer ? \"%d\" : \"%s\", arg)`"
  ],
  "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/util/IllegalFormatConversionException.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2024-02-14",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}