{"record":{"id":"4e622ed28537f630","repo":"apache/hadoop","slug":"key-null","errorCode":null,"errorMessage":"key == null","messagePattern":"key == null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/LightWeightGSet.java","lineNumber":130,"sourceCode":"  public int size() {\n    return size;\n  }\n\n  protected int getIndex(final K key) {\n    return key.hashCode() & hash_mask;\n  }\n\n  protected E convert(final LinkedElement e){\n    @SuppressWarnings(\"unchecked\")\n    final E r = (E)e;\n    return r;\n  }\n\n  @Override\n  public E get(final K key) {\n    //validate key\n    if (key == null) {\n      throw new NullPointerException(\"key == null\");\n    }\n\n    //find element\n    final int index = getIndex(key);\n    for(LinkedElement e = entries[index]; e != null; e = e.getNext()) {\n      if (e.equals(key)) {\n        return convert(e);\n      }\n    }\n    //element not found\n    return null;\n  }\n\n  @Override\n  public boolean contains(final K key) {\n    return get(key) != null;\n  }\n","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/LightWeightGSet.java#L112-L148","documentation":"LightWeightGSet, Hadoop's chained hash set behind hot structures like the NameNode INode map, has no null-key semantics: get(K) throws NullPointerException(\"key == null\") before any hashing. The explicit check fails fast with a searchable message instead of an opaque NPE from inside the hashing logic.","triggerScenarios":"Calling gset.get(null) - a null identifier (inode name, block id) propagated from a failed parse or an upstream lookup that returned null.","commonSituations":"Refactors that made an identifier optional; a lookup-by-name where the name was never validated; code assuming the set tolerates null keys like java.util.HashMap.","solutions":["Use the stack trace to find the caller passing null and null-check the identifier at its source.","Give null a real meaning at the boundary: skip the lookup or throw a descriptive domain exception.","Never store or query null keys in GSet-based structures."],"exampleFix":"// before\nINode node = inodes.get(pathComponent); // pathComponent may be null\n\n// after\nINode node = (pathComponent != null) ? inodes.get(pathComponent) : null;","handlingStrategy":"validation","validationCode":"if (key == null) {\n  return null; // or throw a domain exception describing the missing identifier\n}\nreturn gset.get(key);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate identifiers at the parse/lookup boundary so null never reaches the data structure.","Prefer Objects.requireNonNull(x, \"name\") at assignment sites to fail with context."],"tags":["collections","null-safety","hadoop-common"],"backgroundTag":"null-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}