{"record":{"id":"edabeec42a425d45","repo":"apache/hadoop","slug":"illegal-load-factor-loadfactor","errorCode":null,"errorMessage":"Illegal load factor: \" + loadFactor","messagePattern":"Illegal load factor: \" \\+ loadFactor","errorType":"exception","errorClass":"HadoopIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/LightWeightResizableGSet.java","lineNumber":72,"sourceCode":"   */\n  static final float DEFAULT_LOAD_FACTOR = 0.75f;\n\n  /** Size of the entry table. */\n  private int capacity;\n\n  /**\n   * The load factor for the hash set.\n   */\n  private final float loadFactor;\n  private int threshold;\n\n  public LightWeightResizableGSet(int initCapacity, float loadFactor) {\n    if (initCapacity < 0) {\n      throw new HadoopIllegalArgumentException(\"Illegal initial capacity: \" +\n          initCapacity);\n    }\n    if (loadFactor <= 0 || loadFactor > 1.0f) {\n      throw new HadoopIllegalArgumentException(\"Illegal load factor: \" +\n          loadFactor);\n    }\n    this.capacity = actualArrayLength(initCapacity);\n    this.hash_mask = capacity - 1;\n    this.loadFactor = loadFactor;\n    this.threshold = (int) (capacity * loadFactor);\n\n    entries = new LinkedElement[capacity];\n  }\n\n  public LightWeightResizableGSet() {\n    this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR);\n  }\n\n  public LightWeightResizableGSet(int initCapacity) {\n    this(initCapacity, DEFAULT_LOAD_FACTOR);\n  }\n","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/LightWeightResizableGSet.java#L54-L90","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use a load factor in (0, 1] — 0.75f is the standard default","Convert percentage configs to a fraction: loadFactor = percent / 100.0f","Validate config-sourced floats at load time with a clear error naming the property"],"exampleFix":"// before\nfloat lf = conf.getFloat(\"mymap.loadfactor\", 75);\nnew LightWeightResizableGSet(16, lf);\n\n// after\nfloat pct = conf.getFloat(\"mymap.loadfactor.percent\", 75);\nnew LightWeightResizableGSet(16, Math.min(1.0f, Math.max(0.05f, pct / 100.0f)));","handlingStrategy":"validation","validationCode":"float lf = conf.getFloat(\"mymap.loadfactor\", 0.75f);\nif (lf <= 0f || lf > 1.0f) throw new IllegalArgumentException(\"mymap.loadfactor must be in (0,1]: \" + lf);\nnew LightWeightResizableGSet<>(16, lf);","typeGuard":null,"tryCatchPattern":"try { set = new LightWeightResizableGSet<>(16, lf); } catch (HadoopIllegalArgumentException e) { throw new IllegalArgumentException(\"Bad GSet load factor config: \" + e.getMessage(), e); }","preventionTips":["Document load-factor configs as fractions, and convert percent keys with /100.0f","Validate floats from config before constructor calls","Remember 1.0f is legal, 0.0f is not"],"tags":["hadoop","java","gset","load-factor","constructor"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}