apache/hadoop · error · IllegalArgumentException
Illegal minload factor: {}
Error message
Illegal minload factor: {} What it means
The second constructor validation in LightWeightHashSet: minLoadFactor must satisfy 0 < minLoadFactor <= maxLoadFactor, since it computes the shrink threshold below which the bucket array is contracted. Violating the ordering (min > max) or using a non-positive min throws IllegalArgumentException immediately.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/LightWeightHashSet.java:117
/**
* @param initCapacity
* Recommended size of the internal array.
* @param maxLoadFactor
* used to determine when to expand the internal array
* @param minLoadFactor
* used to determine when to shrink the internal array
*/
@SuppressWarnings("unchecked")
public LightWeightHashSet(int initCapacity, float maxLoadFactor,
float minLoadFactor) {
if (maxLoadFactor <= 0 || maxLoadFactor > 1.0f)
throw new IllegalArgumentException("Illegal maxload factor: "
+ maxLoadFactor);
if (minLoadFactor <= 0 || minLoadFactor > maxLoadFactor)
throw new IllegalArgumentException("Illegal minload factor: "
+ minLoadFactor);
this.initialCapacity = computeCapacity(initCapacity);
this.capacity = this.initialCapacity;
this.hash_mask = capacity - 1;
this.maxLoadFactor = maxLoadFactor;
this.expandThreshold = (int) (capacity * maxLoadFactor);
this.minLoadFactor = minLoadFactor;
this.shrinkThreshold = (int) (capacity * minLoadFactor);
entries = new LinkedElement[capacity];
if (LOG.isDebugEnabled()) {
LOG.debug("initial capacity=" + initialCapacity + ", max load factor= "
+ maxLoadFactor + ", min load factor= " + minLoadFactor);
}
}
View on GitHub (pinned to 2add963021)
Solutions
- Order the arguments correctly and keep min within (0, max]; defaults are DEFAULT_MAX_LOAD_FACTOR = 0.75f and DEFAUT_MIN_LOAD_FACTOR = 0.2f.
- Name intermediate variables (float maxLoadFactor, float minLoadFactor) at the call site so swaps are visible in review.
- Range-check both factors at the boundary where external config enters the code.
Example fix
// before new LightWeightHashSet<>(16, 0.2f, 0.75f); // min > max -> IllegalArgumentException // after float maxLoadFactor = 0.75f; float minLoadFactor = 0.2f; // must satisfy 0 < min <= max new LightWeightHashSet<>(16, maxLoadFactor, minLoadFactor);
Defensive patterns
Strategy: validation
Validate before calling
static boolean isValidMinLoadFactor(float min, float max) {
return min > 0f && min <= max;
}
// before constructing:
if (!isValidMinLoadFactor(min, max)) throw new IllegalArgumentException("min must be in (0,max]: " + min + ", max=" + max); Type guard
static boolean isValidMinLoadFactor(float min, float max) { return min > 0f && min <= max; } Prevention
- Name constructor arguments at call sites (maxLoadFactor, minLoadFactor) so swaps are caught in review.
- Remember the defaults: max 0.75f, min 0.2f - copy them rather than reinventing.
- Range-check both factors together where config is read.
When it happens
Trigger: The 3-arg constructor with minLoadFactor <= 0, or minLoadFactor > maxLoadFactor - e.g., (16, 0.25f, 0.5f) or (16, 0.75f, 2.0f). Frequently the result of swapped 2nd/3rd arguments.
Common situations: Argument-order mistakes when hand-writing the constructor call; percentages again (min 20 with max 0.75f); refactors that changed parameter order between versions of internal wrappers.
Related errors
- Illegal maxload factor: {}
- Path must be absolute: " + path
- Copy destination must be different from source for %s.
- Block size must be greater than 0
- Replication must be greater than 0
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/2299b063438ac5d5.
Report an issue: GitHub.