{"record":{"id":"7f2949141a74651b","repo":"apache/hadoop","slug":"illegal-maxload-factor","errorCode":null,"errorMessage":"Illegal maxload factor: {}","messagePattern":"Illegal maxload 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":113,"sourceCode":"  private final int expandMultiplier = 2;\n\n  private int expandThreshold;\n  private int shrinkThreshold;\n\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= \"","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/LightWeightHashSet.java#L95-L131","documentation":"LightWeightHashSet (and its subclass LightWeightLinkedSet) validates constructor arguments: maxLoadFactor must satisfy 0 < maxLoadFactor <= 1.0 because it is multiplied by bucket capacity to compute the expand threshold. Anything outside that range is rejected immediately with IllegalArgumentException - a fail-fast programming error, not a runtime environment condition.","triggerScenarios":"Invoking the 3-arg constructor new LightWeightHashSet<>(initCapacity, maxLoadFactor, minLoadFactor) (or LightWeightLinkedSet with the same args) with maxLoadFactor <= 0 (0f, negative) or > 1.0f (1.5f, 75f). Common source: passing a percentage where a fraction is expected.","commonSituations":"Porting tuning values from another hash table that expresses load factor as a percent (75 instead of 0.75f); a config lookup returning a -1 'unset' sentinel that flows into the constructor; unit tests probing boundaries.","solutions":["Pass maxLoadFactor as a fraction in (0, 1.0]; use the library defaults DEFAULT_MAX_LOAD_FACTOR = 0.75f when unsure.","If the value arrives as a percentage from config, divide by 100 and range-check before constructing.","Add a constructor-argument unit test with boundary values (0, 1.0, just above 1.0) in the wrapper that builds the set."],"exampleFix":"// before\nfloat pct = conf.getFloat(\"my.hash.load.percent\", 75); // percent semantics\nnew LightWeightLinkedSet<>(16, pct, 20); // 75 > 1.0f -> IllegalArgumentException\n\n// after\nfloat max = conf.getFloat(\"my.hash.load.percent\", 75) / 100f;\nfloat min = conf.getFloat(\"my.hash.min.load.percent\", 20) / 100f;\nif (max <= 0f || max > 1f || min <= 0f || min > max) {\n  throw new IllegalArgumentException(\"load factors out of range: max=\" + max + \", min=\" + min);\n}\nnew LightWeightLinkedSet<>(16, max, min);","handlingStrategy":"validation","validationCode":"static boolean isValidMaxLoadFactor(float f) {\n  return f > 0f && f <= 1.0f;\n}\n// before constructing:\nif (!isValidMaxLoadFactor(max)) throw new IllegalArgumentException(\"max load factor must be in (0,1]: \" + max);","typeGuard":"static boolean isValidMaxLoadFactor(float f) { return f > 0f && f <= 1.0f; }","tryCatchPattern":null,"preventionTips":["Treat load factors as fractions (0.75f), never percentages (75).","Validate externally sourced numeric config at parse time, before it reaches constructors.","Boundary-test wrapper constructors with 0, 1.0, and just-above-1.0 values."],"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"}