{"record":{"id":"e747a355aa5c7def","repo":"apache/hadoop","slug":"null-element-is-not-supported-e747a3","errorCode":null,"errorMessage":"Null element is not supported.","messagePattern":"Null element is not supported\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/LightWeightLinkedSet.java","lineNumber":90,"sourceCode":"    head = null;\n    tail = null;\n    bookmark = new LinkedSetIterator();\n  }\n\n  public LightWeightLinkedSet() {\n    this(MINIMUM_CAPACITY, DEFAULT_MAX_LOAD_FACTOR, DEFAUT_MIN_LOAD_FACTOR);\n  }\n\n  /**\n   * Add given element to the hash table\n   *\n   * @return true if the element was not present in the table, false otherwise\n   */\n  @Override\n  protected boolean addElem(final T element) {\n    // validate element\n    if (element == null) {\n      throw new IllegalArgumentException(\"Null element is not supported.\");\n    }\n    // find hashCode & index\n    final int hashCode = element.hashCode();\n    final int index = getIndex(hashCode);\n    // return false if already present\n    if (getContainedElem(index, element, hashCode) != null) {\n      return false;\n    }\n\n    modification++;\n    size++;\n\n    // update bucket linked list\n    DoubleLinkedElement<T> le = new DoubleLinkedElement<T>(element, hashCode);\n    le.next = entries[index];\n    entries[index] = le;\n\n    // insert to the end of the all-element linked list","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/LightWeightLinkedSet.java#L72-L108","documentation":"LightWeightLinkedSet overrides addElem (the insert used by add/addAll) and repeats the null rejection: a null element throws IllegalArgumentException before hashing. Same policy as the parent LightWeightHashSet (error 3245) - insertion order tracking via the doubly-linked list has no representation for null.","triggerScenarios":"linkedSet.add(null) or linkedSet.addAll(collectionContainingNull) - e.g., feeding lease/path trackers with values obtained from map.get() misses or deserialized nullable fields.","commonSituations":"Porting insertion-order-sensitive code from LinkedHashSet (which permits one null) to LightWeightLinkedSet for memory; batch inserts from user input; null-producing deserializers.","solutions":["Guard inserts: if (e != null) set.add(e);","Pre-filter: set.addAll(c.stream().filter(Objects::nonNull).collect(Collectors.toList()));","Use LinkedHashSet if null membership must be representable."],"exampleFix":"// before\nnames.forEach(set::add); // any null -> IllegalArgumentException\n\n// after\nnames.stream().filter(Objects::nonNull).forEach(set::add);","handlingStrategy":"type-guard","validationCode":"values.stream().filter(Objects::nonNull).forEach(orderedSet::add);","typeGuard":"static <T> Predicate<T> nonNull() { return Objects::nonNull; } // filter before add/addAll","tryCatchPattern":null,"preventionTips":["Remember LinkedHashSet permits one null but LightWeightLinkedSet permits none - audit ports.","Guard optional-value adds with if-present checks.","Filter deserialized/user input before bulk insertion."],"tags":["null-safety","set","illegal-argument","add","linked-set"],"backgroundTag":"null-argument-rejected","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}