{"record":{"id":"2299b063438ac5d5","repo":"apache/hadoop","slug":"illegal-minload-factor","errorCode":null,"errorMessage":"Illegal minload factor: {}","messagePattern":"Illegal minload factor: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/LightWeightHashSet.java","lineNumber":117,"sourceCode":"\n  /**\n   * @param initCapacity\n   *          Recommended size of the internal array.\n   * @param maxLoadFactor\n   *          used to determine when to expand the internal array\n   * @param minLoadFactor\n   *          used to determine when to shrink the internal array\n   */\n  @SuppressWarnings(\"unchecked\")\n  public LightWeightHashSet(int initCapacity, float maxLoadFactor,\n      float minLoadFactor) {\n\n    if (maxLoadFactor <= 0 || maxLoadFactor > 1.0f)\n      throw new IllegalArgumentException(\"Illegal maxload factor: \"\n          + maxLoadFactor);\n\n    if (minLoadFactor <= 0 || minLoadFactor > maxLoadFactor)\n      throw new IllegalArgumentException(\"Illegal minload factor: \"\n          + minLoadFactor);\n\n    this.initialCapacity = computeCapacity(initCapacity);\n    this.capacity = this.initialCapacity;\n    this.hash_mask = capacity - 1;\n\n    this.maxLoadFactor = maxLoadFactor;\n    this.expandThreshold = (int) (capacity * maxLoadFactor);\n    this.minLoadFactor = minLoadFactor;\n    this.shrinkThreshold = (int) (capacity * minLoadFactor);\n\n    entries = new LinkedElement[capacity];\n    if (LOG.isDebugEnabled()) {\n      LOG.debug(\"initial capacity=\" + initialCapacity + \", max load factor= \"\n          + maxLoadFactor + \", min load factor= \" + minLoadFactor);\n    }\n  }\n","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/LightWeightHashSet.java#L99-L135","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nnew LightWeightHashSet<>(16, 0.2f, 0.75f); // min > max -> IllegalArgumentException\n\n// after\nfloat maxLoadFactor = 0.75f;\nfloat minLoadFactor = 0.2f; // must satisfy 0 < min <= max\nnew LightWeightHashSet<>(16, maxLoadFactor, minLoadFactor);","handlingStrategy":"validation","validationCode":"static boolean isValidMinLoadFactor(float min, float max) {\n  return min > 0f && min <= max;\n}\n// before constructing:\nif (!isValidMinLoadFactor(min, max)) throw new IllegalArgumentException(\"min must be in (0,max]: \" + min + \", max=\" + max);","typeGuard":"static boolean isValidMinLoadFactor(float min, float max) { return min > 0f && min <= max; }","tryCatchPattern":null,"preventionTips":["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."],"tags":["validation","constructor","illegal-argument","hash-table"],"backgroundTag":"invalid-argument-range","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}