apache/hadoop · error · NullPointerException

ArrayList<Key> can not be null

Error message

ArrayList<Key> can not be null

What it means

The List overload mirrors the Collection one, but its message still says 'ArrayList<Key>' because the API was originally written against ArrayList. It throws NullPointerException when the List reference itself is null, before the iteration starts.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/RetouchedBloomFilter.java:172

   * @param coll The collection of false positive.
   */
  public void addFalsePositive(Collection<Key> coll) {
    if (coll == null) {
      throw new NullPointerException("Collection<Key> can not be null");
    }
    
    for (Key k : coll) {
      addFalsePositive(k);
    }
  }

  /**
   * Adds a list of false positive information to <i>this</i> retouched Bloom filter.
   * @param keys The list of false positive.
   */
  public void addFalsePositive(List<Key> keys) {
    if (keys == null) {
      throw new NullPointerException("ArrayList<Key> can not be null");
    }

    for (Key k : keys) {
      addFalsePositive(k);
    }
  }

  /**
   * Adds an array of false positive information to <i>this</i> retouched Bloom filter.
   * @param keys The array of false positive.
   */
  public void addFalsePositive(Key[] keys) {
    if (keys == null) {
      throw new NullPointerException("Key[] can not be null");
    }

    for (int i = 0; i < keys.length; i++) {
      addFalsePositive(keys[i]);

View on GitHub (pinned to 2add963021)

Solutions

  1. Pass Collections.emptyList() or a new ArrayList<Key>() when the list is absent
  2. Null-check the List before the call
  3. Make your own helpers never return null collections

Example fix

// before
rbf.addFalsePositive(keys); // keys may be null -> NPE

// after
List<Key> safe = (keys == null) ? Collections.<Key>emptyList() : keys;
rbf.addFalsePositive(safe);
Defensive patterns

Strategy: validation

Validate before calling

List<Key> safe = (keys == null) ? Collections.<Key>emptyList() : keys;
rbf.addFalsePositive(safe);

Prevention

When it happens

Trigger: rbf.addFalsePositive((List<Key>) null); a List local that an early-return path left null; chaining a helper whose contract permits null returns.

Common situations: Refactors from ArrayList parameters to List with partial null handling; builder helpers that return null instead of an empty list on 'no data'.

Related errors


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