{"record":{"id":"124f8aae9124ac6a","repo":"apache/kafka","slug":"illegal-metadatarecoverystrategy","errorCode":null,"errorMessage":"Illegal MetadataRecoveryStrategy: {}","messagePattern":"Illegal MetadataRecoveryStrategy: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/MetadataRecoveryStrategy.java","lineNumber":41,"sourceCode":" */\npublic enum MetadataRecoveryStrategy {\n    NONE(\"none\"),\n    REBOOTSTRAP(\"rebootstrap\");\n\n    public final String name;\n\n    MetadataRecoveryStrategy(String name) {\n        this.name = name;\n    }\n\n    public static MetadataRecoveryStrategy forName(String name) {\n        if (name == null) {\n            throw new IllegalArgumentException(\"Illegal MetadataRecoveryStrategy: null\");\n        }\n        try {\n            return MetadataRecoveryStrategy.valueOf(name.toUpperCase(Locale.ROOT));\n        } catch (IllegalArgumentException e) {\n            throw new IllegalArgumentException(\"Illegal MetadataRecoveryStrategy: \" + name);\n        }\n    }\n}\n","sourceCodeStart":23,"sourceCodeEnd":45,"githubUrl":"https://github.com/apache/kafka/blob/996fb4585aa1bcc8980b0e1b8d6b168b986cd979/clients/src/main/java/org/apache/kafka/clients/MetadataRecoveryStrategy.java#L23-L45","documentation":"Thrown by MetadataRecoveryStrategy.forName(String) when the supplied name is null or does not match any enum constant of MetadataRecoveryStrategy after uppercasing. The method resolves a recovery strategy by name (e.g. NONE, FETCH) and wraps the underlying Enum.valueOf failure in an IllegalArgumentException so callers get a single, consistent error type for both null input and bad names.","triggerScenarios":"Calling MetadataRecoveryStrategy.forName(name) with a null argument, or with a string that is not a valid enum constant name (e.g. \"FOO\", empty string, or a typo like \"nones\"). Also triggered by passing a config-derived string that has not been validated against the known strategy names.","commonSituations":"Misconfigured client property for metadata recovery strategy (typo in config key value), version mismatch where a strategy name was renamed or removed between Kafka versions, or programmatic construction where the name comes from an external/untrusted source without validation.","solutions":["Check the strategy name spelling against the MetadataRecoveryStrategy enum constants (NONE, FETCH, etc.) and correct the config value.","If the name comes from external input, validate it against MetadataRecoveryStrategy.values() before calling forName.","On Kafka version upgrades, verify the strategy name still exists in the target version's enum."],"exampleFix":"// before\nMetadataRecoveryStrategy.forName(userInput); // may throw\n\n// after\nif (userInput == null || Arrays.stream(MetadataRecoveryStrategy.values())\n        .noneMatch(s -> s.name().equalsIgnoreCase(userInput))) {\n    throw new IllegalArgumentException(\"Unknown strategy: \" + userInput);\n}\nMetadataRecoveryStrategy.forName(userInput);","handlingStrategy":"validation","validationCode":"import java.util.Arrays;\nboolean ok = name != null && Arrays.stream(MetadataRecoveryStrategy.values())\n    .anyMatch(s -> s.name().equalsIgnoreCase(name));\nif (!ok) throw new IllegalArgumentException(\"Invalid strategy: \" + name);","typeGuard":"static boolean isValidStrategyName(String name) {\n    if (name == null) return false;\n    return Arrays.stream(MetadataRecoveryStrategy.values())\n        .anyMatch(s -> s.name().equalsIgnoreCase(name));\n}","tryCatchPattern":"try {\n    MetadataRecoveryStrategy.forName(name);\n} catch (IllegalArgumentException e) {\n    // log and fall back to default strategy or surface config error\n}","preventionTips":["Validate config-derived strings against the enum before calling forName.","Document valid strategy names in config tooling/help text.","On version upgrades, diff the enum to catch renamed/removed constants."],"tags":["config","validation","metadata"],"backgroundTag":null,"analyzedSha":"996fb4585aa1bcc8980b0e1b8d6b168b986cd979","analyzedAt":"2026-08-11T22:03:28.655Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}