{"record":{"id":"32d0abf795e14558","repo":"apache/kafka","slug":"illegal-metadatarecoverystrategy-null","errorCode":null,"errorMessage":"Illegal MetadataRecoveryStrategy: null","messagePattern":"Illegal MetadataRecoveryStrategy: null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/MetadataRecoveryStrategy.java","lineNumber":36,"sourceCode":"\nimport java.util.Locale;\n\n/**\n * Defines the strategies which clients can follow to deal with the situation when none of the known nodes is available.\n */\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":18,"sourceCodeEnd":45,"githubUrl":"https://github.com/apache/kafka/blob/996fb4585aa1bcc8980b0e1b8d6b168b986cd979/clients/src/main/java/org/apache/kafka/clients/MetadataRecoveryStrategy.java#L18-L45","documentation":"IllegalArgumentException from MetadataRecoveryStrategy.forName when the supplied name is null, or does not match one of the enum constants NONE/REBOOTSTRAP (compared case-insensitively via toUpperCase(ROOT)). Used by ClientUtils.createNetworkClient to convert the metadata.recovery.strategy config into the enum. The exception propagates wrapped in the NetworkClient KafkaException (error 17) if not handled earlier.","triggerScenarios":"forName(null) throws immediately (line 39); forName(\"<unknown>\") fails valueOf and is rethrown at line 44. Triggered when metadata.recovery.strategy is unset/empty or set to a value other than 'none'/'rebootstrap' (case-insensitive).","commonSituations":"Typo in metadata.recovery.strategy (e.g. 're-boot-strap'); value set to an old name removed in an upgrade; empty string from a templated config; passing a null from a defaulting bug.","solutions":["Set metadata.recovery.strategy to either 'none' or 'rebootstrap' (case-insensitive).","If unset, rely on the documented default rather than passing a guessed value.","Validate before constructing the client: MetadataRecoveryStrategy.forName on a known-good literal.","On version upgrades, check the release notes for renamed/removed strategy values."],"exampleFix":"# before\nmetadata.recovery.strategy=re-boot-strap\n# after\nmetadata.recovery.strategy=rebootstrap","handlingStrategy":"type-guard","validationCode":"String name = config.getString(CommonClientConfigs.METADATA_RECOVERY_STRATEGY_CONFIG);\nif (name == null || (!name.equalsIgnoreCase(\"none\") && !name.equalsIgnoreCase(\"rebootstrap\")))\n  throw new ConfigException(CommonClientConfigs.METADATA_RECOVERY_STRATEGY_CONFIG, name, \"must be 'none' or 'rebootstrap'\");","typeGuard":"// Narrow the string to the allowed set before calling forName\nstatic final Set<String> ALLOWED = Set.of(\"none\", \"rebootstrap\");\nboolean isKnownStrategy(String s) { return s != null && ALLOWED.contains(s.toLowerCase(Locale.ROOT)); }","tryCatchPattern":"try { MetadataRecoveryStrategy.forName(name); } catch (IllegalArgumentException e) { /* set metadata.recovery.strategy to 'none' or 'rebootstrap' */ }","preventionTips":["Use only 'none' or 'rebootstrap' (case-insensitive) for metadata.recovery.strategy.","Rely on the documented default instead of guessing a value.","Re-check valid values on Kafka version upgrades."],"tags":["kafka-client","config","metadata","enum"],"backgroundTag":null,"analyzedSha":"996fb4585aa1bcc8980b0e1b8d6b168b986cd979","analyzedAt":"2026-08-11T22:03:28.655Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}