{"record":{"id":"4b9149da1faa538a","repo":"pinpoint-apm/pinpoint","slug":"illegal-capacity-initialcapacity","errorCode":null,"errorMessage":"Illegal Capacity: +initialCapacity","messagePattern":"Illegal Capacity: \\+initialCapacity","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"commons/src/main/java/com/navercorp/pinpoint/common/util/apache/IntHashMap.java","lineNumber":123,"sourceCode":"     *   than zero.\n     */\n    public IntHashMap(int initialCapacity) {\n        this(initialCapacity, 0.75f);\n    }\n\n    /**\n     * <p>Constructs a new, empty hashtable with the specified initial\n     * capacity and the specified load factor.</p>\n     *\n     * @param initialCapacity the initial capacity of the hashtable.\n     * @param loadFactor the load factor of the hashtable.\n     * @throws IllegalArgumentException  if the initial capacity is less\n     *             than zero, or if the load factor is nonpositive.\n     */\n    public IntHashMap(int initialCapacity, float loadFactor) {\n        super();\n        if (initialCapacity < 0) {\n            throw new IllegalArgumentException(\"Illegal Capacity: \" + initialCapacity);\n        }\n        if (loadFactor <= 0) {\n            throw new IllegalArgumentException(\"Illegal Load: \" + loadFactor);\n        }\n        if (initialCapacity == 0) {\n            initialCapacity = 1;\n        }\n\n        this.loadFactor = loadFactor;\n        table = new Entry[initialCapacity];\n        threshold = (int) (initialCapacity * loadFactor);\n    }\n\n    /**\n     * <p>Returns the number of keys in this hashtable.</p>\n     *\n     * @return  the number of keys in this hashtable.\n     */","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/pinpoint-apm/pinpoint/blob/744c3d3075e595656abb1ae331ad2c0e4c9eb996/commons/src/main/java/com/navercorp/pinpoint/common/util/apache/IntHashMap.java#L105-L141","documentation":"IntHashMap(int initialCapacity, float loadFactor) is a Hashtable-style primitive-int-key map. A negative initialCapacity is rejected with IllegalArgumentException ('Illegal Capacity: ...') because the internal bucket array cannot have negative size. A capacity of 0 is tolerated and bumped to 1.","triggerScenarios":"Constructing IntHashMap with a negative initialCapacity, e.g. from a computed size, a negative cache-size config, or a subtraction that underflowed.","commonSituations":"Sizing the map from (expected - buffer) where buffer exceeded expected; misconfigured capacity property parsed as negative.","solutions":["Pass a non-negative capacity; clamp with Math.max(0, size)","Validate any capacity config value at load time","Use the no-arg constructor if the size is unknown"],"exampleFix":"// before\nIntHashMap map = new IntHashMap(size, 0.75f); // size = -10\n// after\nIntHashMap map = new IntHashMap(Math.max(0, size), 0.75f);","handlingStrategy":"validation","validationCode":"if (initialCapacity < 0) throw new IllegalArgumentException(\"initialCapacity must be >= 0\");\nIntHashMap map = new IntHashMap(initialCapacity, 0.75f);","typeGuard":null,"tryCatchPattern":"try {\n    map = new IntHashMap(initialCapacity, loadFactor);\n} catch (IllegalArgumentException e) {\n    logger.warn(\"IntHashMap capacity invalid: {}\", e.getMessage());\n    map = new IntHashMap();\n}","preventionTips":["Clamp computed sizes with Math.max(0, size)","Prefer the no-arg constructor when size is unknown","Validate capacity configs at load time"],"tags":["collections","argument-check","constructor"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"744c3d3075e595656abb1ae331ad2c0e4c9eb996","analyzedAt":"2026-09-07T18:48:45.289Z","contentChangedAt":"2026-09-07T18:48:45.289Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}