apache/hadoop · error · IllegalArgumentException

Null element is not supported.

Error message

Null element is not supported.

What it means

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.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/LightWeightLinkedSet.java:90

    head = null;
    tail = null;
    bookmark = new LinkedSetIterator();
  }

  public LightWeightLinkedSet() {
    this(MINIMUM_CAPACITY, DEFAULT_MAX_LOAD_FACTOR, DEFAUT_MIN_LOAD_FACTOR);
  }

  /**
   * Add given element to the hash table
   *
   * @return true if the element was not present in the table, false otherwise
   */
  @Override
  protected boolean addElem(final T element) {
    // validate element
    if (element == null) {
      throw new IllegalArgumentException("Null element is not supported.");
    }
    // find hashCode & index
    final int hashCode = element.hashCode();
    final int index = getIndex(hashCode);
    // return false if already present
    if (getContainedElem(index, element, hashCode) != null) {
      return false;
    }

    modification++;
    size++;

    // update bucket linked list
    DoubleLinkedElement<T> le = new DoubleLinkedElement<T>(element, hashCode);
    le.next = entries[index];
    entries[index] = le;

    // insert to the end of the all-element linked list

View on GitHub (pinned to 2add963021)

Solutions

  1. Guard inserts: if (e != null) set.add(e);
  2. Pre-filter: set.addAll(c.stream().filter(Objects::nonNull).collect(Collectors.toList()));
  3. Use LinkedHashSet if null membership must be representable.

Example fix

// before
names.forEach(set::add); // any null -> IllegalArgumentException

// after
names.stream().filter(Objects::nonNull).forEach(set::add);
Defensive patterns

Strategy: type-guard

Validate before calling

values.stream().filter(Objects::nonNull).forEach(orderedSet::add);

Type guard

static <T> Predicate<T> nonNull() { return Objects::nonNull; } // filter before add/addAll

Prevention

When it happens

Trigger: linkedSet.add(null) or linkedSet.addAll(collectionContainingNull) - e.g., feeding lease/path trackers with values obtained from map.get() misses or deserialized nullable fields.

Common situations: Porting insertion-order-sensitive code from LinkedHashSet (which permits one null) to LightWeightLinkedSet for memory; batch inserts from user input; null-producing deserializers.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/e747a355aa5c7def. Report an issue: GitHub.