{"record":{"id":"21932a9f47876272","repo":"pinpoint-apm/pinpoint","slug":"illegalargumentexception-21932a","errorCode":null,"errorMessage":"IllegalArgumentException","messagePattern":"IllegalArgumentException","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/jsr166/ConcurrentWeakHashMap.java","lineNumber":675,"sourceCode":"     * Creates a new, empty map with the specified initial\n     * capacity, load factor and concurrency level.\n     *\n     * @param initialCapacity the initial capacity. The implementation\n     * performs internal sizing to accommodate this many elements.\n     * @param loadFactor  the load factor threshold, used to control resizing.\n     * Resizing may be performed when the average number of elements per\n     * bin exceeds this threshold.\n     * @param concurrencyLevel the estimated number of concurrently\n     * updating threads. The implementation performs internal sizing\n     * to try to accommodate this many threads.\n     * @throws IllegalArgumentException if the initial capacity is\n     * negative or the load factor or concurrencyLevel are\n     * nonpositive.\n     */\n    public ConcurrentWeakHashMap(int initialCapacity,\n                                 float loadFactor, int concurrencyLevel) {\n        if (!(loadFactor > 0) || initialCapacity < 0 || concurrencyLevel <= 0)\n            throw new IllegalArgumentException();\n\n        if (concurrencyLevel > MAX_SEGMENTS)\n            concurrencyLevel = MAX_SEGMENTS;\n\n        // Find power-of-two sizes best matching arguments\n        int sshift = 0;\n        int ssize = 1;\n        while (ssize < concurrencyLevel) {\n            ++sshift;\n            ssize <<= 1;\n        }\n        segmentShift = 32 - sshift;\n        segmentMask = ssize - 1;\n        this.segments = Segment.newArray(ssize);\n\n        if (initialCapacity > MAXIMUM_CAPACITY)\n            initialCapacity = MAXIMUM_CAPACITY;\n        int c = initialCapacity / ssize;","sourceCodeStart":657,"sourceCodeEnd":693,"githubUrl":"https://github.com/pinpoint-apm/pinpoint/blob/744c3d3075e595656abb1ae331ad2c0e4c9eb996/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/jsr166/ConcurrentWeakHashMap.java#L657-L693","documentation":"ConcurrentWeakHashMap (a JSR-166 style concurrent weak map) validates its constructor arguments up front and throws an unspecific IllegalArgumentException when the load factor is not greater than zero, the initial capacity is negative, or the concurrency level is not positive. It fails fast rather than producing a broken table.","triggerScenarios":"new ConcurrentWeakHashMap(int initialCapacity, float loadFactor, int concurrencyLevel) called with loadFactor <= 0, initialCapacity < 0, or concurrencyLevel <= 0.","commonSituations":"Config values read from properties/XML (capacity or concurrency level) that are 0 or negative due to a parsing bug or bad config; passing a load factor of 0 or a typo like -1 for capacity.","solutions":["Check the three constructor arguments before construction; ensure loadFactor > 0, initialCapacity >= 0, concurrencyLevel > 0","Fix the config source that produced the zero/negative value (e.g. a missing default becoming 0)","Use the no-arg or (int initialCapacity) constructors when custom tuning is not needed"],"exampleFix":"// before\nint level = Integer.parseInt(props.getProperty(\"map.level\")); // 0 when unset\nmap = new ConcurrentWeakHashMap(1024, 0.75f, level);\n// after\nint level = Math.max(1, Integer.parseInt(props.getProperty(\"map.level\", \"16\")));\nmap = new ConcurrentWeakHashMap(Math.max(0, 1024), 0.75f, level);","handlingStrategy":"validation","validationCode":"static ConcurrentWeakHashMap<String,Object> safeCreate(int cap, float lf, int level) {\n    if (lf <= 0f || cap < 0 || level <= 0) throw new IllegalArgumentException(\"bad map args: cap=\" + cap + \" lf=\" + lf + \" level=\" + level);\n    return new ConcurrentWeakHashMap<>(cap, lf, level);\n}","typeGuard":null,"tryCatchPattern":"try { map = new ConcurrentWeakHashMap<>(cap, lf, level); } catch (IllegalArgumentException e) { map = new ConcurrentWeakHashMap<>(); }","preventionTips":["Never feed raw config integers into the constructor without clamping to sane ranges","Default concurrencyLevel to 16 and loadFactor to 0.75f unless profiling shows a need","Prefer the simpler constructors unless tuning is measured"],"tags":["java","concurrency","illegal-argument","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-14T05:17:10.506Z"}