{"record":{"id":"bb0b1853aa76a928","repo":"apache/hadoop","slug":"attributes-cannot-have-a-null-key","errorCode":null,"errorMessage":"attributes cannot have a NULL key","messagePattern":"attributes cannot have a NULL key","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/KeyProvider.java","lineNumber":362,"sourceCode":"    public Options setCipher(String cipher) {\n      this.cipher = cipher;\n      return this;\n    }\n\n    public Options setBitLength(int bitLength) {\n      this.bitLength = bitLength;\n      return this;\n    }\n\n    public Options setDescription(String description) {\n      this.description = description;\n      return this;\n    }\n\n    public Options setAttributes(Map<String, String> attributes) {\n      if (attributes != null) {\n        if (attributes.containsKey(null)) {\n          throw new IllegalArgumentException(\"attributes cannot have a NULL key\");\n        }\n        this.attributes = new HashMap<String, String>(attributes);\n      }\n      return this;\n    }\n\n    public String getCipher() {\n      return cipher;\n    }\n\n    public int getBitLength() {\n      return bitLength;\n    }\n\n    public String getDescription() {\n      return description;\n    }\n","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/KeyProvider.java#L344-L380","documentation":"KeyProvider.Options.setAttributes copies the caller's attribute map into the options; java.util.HashMap tolerates a null key, but the serialized Metadata format written into the keystore cannot represent one, so a null key is rejected up front with IllegalArgumentException instead of corrupting the store later.","triggerScenarios":"Building the attributes map from parsed key=value strings where an empty left-hand side becomes null; map.put(null, value) from unvalidated input; wrappers that insert a null key as a sentinel.","commonSituations":"Parsing user-supplied attributes (e.g. `hadoop key create -attribute` style input) by splitting on '=' without checking for an empty key side; config-driven attribute maps.","solutions":["Sanitize before calling: drop or reject entries whose key is null or empty","Validate at parse time: every attribute token must contain '=' with a non-empty left-hand side","Use Objects.requireNonNull(key) while building the map to fail at the true source"],"exampleFix":"// before\nMap<String,String> attrs = new HashMap<>();\nattrs.put(null, \"v\"); // slips through HashMap\noptions.setAttributes(attrs);\n\n// after\nMap<String,String> attrs = new HashMap<>();\nattrs.put(\"purpose\", \"v\");\noptions.setAttributes(attrs);","handlingStrategy":"validation","validationCode":"Map<String,String> safe = new LinkedHashMap<>();\nfor (Map.Entry<String,String> e : rawAttributes.entrySet()) {\n  if (e.getKey() == null || e.getKey().isEmpty()) continue; // or throw\n  safe.put(e.getKey(), e.getValue());\n}\noptions.setAttributes(safe);","typeGuard":"static boolean hasNoNullKeys(Map<String,String> attrs) {\n  return attrs == null || !attrs.containsKey(null);\n}","tryCatchPattern":"catch (IllegalArgumentException e) { if (\"attributes cannot have a NULL key\".equals(e.getMessage())) { // fix the attribute map at its source (parser) and rebuild options } else { throw e; } }","preventionTips":["Validate attribute tokens when parsing key=value strings: require non-empty key before '='","Never use null as a map key sentinel","Build attribute maps with Objects.requireNonNull on each key"],"tags":["java","hadoop","key-provider","validation","null-key"],"backgroundTag":"null-map-key","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}