apache/hadoop · error · HadoopIllegalArgumentException

Illegal load factor: " + loadFactor

Error message

Illegal load factor: " + loadFactor

What it means

The second constructor validation in LightWeightResizableGSet: loadFactor must lie in (0.0f, 1.0f], exactly like java.util.HashMap, because threshold = (int)(capacity * loadFactor) drives resizing. Values <= 0 or > 1.0f throw HadoopIllegalArgumentException("Illegal load factor: N"). Note the boundary: 1.0f is allowed, 0.0f is not.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/LightWeightResizableGSet.java:72

   */
  static final float DEFAULT_LOAD_FACTOR = 0.75f;

  /** Size of the entry table. */
  private int capacity;

  /**
   * The load factor for the hash set.
   */
  private final float loadFactor;
  private int threshold;

  public LightWeightResizableGSet(int initCapacity, float loadFactor) {
    if (initCapacity < 0) {
      throw new HadoopIllegalArgumentException("Illegal initial capacity: " +
          initCapacity);
    }
    if (loadFactor <= 0 || loadFactor > 1.0f) {
      throw new HadoopIllegalArgumentException("Illegal load factor: " +
          loadFactor);
    }
    this.capacity = actualArrayLength(initCapacity);
    this.hash_mask = capacity - 1;
    this.loadFactor = loadFactor;
    this.threshold = (int) (capacity * loadFactor);

    entries = new LinkedElement[capacity];
  }

  public LightWeightResizableGSet() {
    this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR);
  }

  public LightWeightResizableGSet(int initCapacity) {
    this(initCapacity, DEFAULT_LOAD_FACTOR);
  }

View on GitHub (pinned to 2add963021)

Solutions

  1. Use a load factor in (0, 1] — 0.75f is the standard default
  2. Convert percentage configs to a fraction: loadFactor = percent / 100.0f
  3. Validate config-sourced floats at load time with a clear error naming the property

Example fix

// before
float lf = conf.getFloat("mymap.loadfactor", 75);
new LightWeightResizableGSet(16, lf);

// after
float pct = conf.getFloat("mymap.loadfactor.percent", 75);
new LightWeightResizableGSet(16, Math.min(1.0f, Math.max(0.05f, pct / 100.0f)));
Defensive patterns

Strategy: validation

Validate before calling

float lf = conf.getFloat("mymap.loadfactor", 0.75f);
if (lf <= 0f || lf > 1.0f) throw new IllegalArgumentException("mymap.loadfactor must be in (0,1]: " + lf);
new LightWeightResizableGSet<>(16, lf);

Try / catch

try { set = new LightWeightResizableGSet<>(16, lf); } catch (HadoopIllegalArgumentException e) { throw new IllegalArgumentException("Bad GSet load factor config: " + e.getMessage(), e); }

Prevention

When it happens

Trigger: new LightWeightResizableGSet(16, 0.0f) or (16, 1.5f); passing a percentage where a fraction is expected (75 instead of 0.75f); a config-sourced float with an unset default like -1.0f.

Common situations: Percent-vs-fraction confusion when a config key is expressed as a percentage; porting HashMap parameters across a refactor; defaults that silently change after an upgrade.

Related errors


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