pinpoint-apm/pinpoint · error · java.lang.IllegalArgumentException
IllegalArgumentException
Error message
IllegalArgumentException
What it means
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.
Source
Thrown at commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/concurrent/jsr166/ConcurrentWeakHashMap.java:675
* Creates a new, empty map with the specified initial
* capacity, load factor and concurrency level.
*
* @param initialCapacity the initial capacity. The implementation
* performs internal sizing to accommodate this many elements.
* @param loadFactor the load factor threshold, used to control resizing.
* Resizing may be performed when the average number of elements per
* bin exceeds this threshold.
* @param concurrencyLevel the estimated number of concurrently
* updating threads. The implementation performs internal sizing
* to try to accommodate this many threads.
* @throws IllegalArgumentException if the initial capacity is
* negative or the load factor or concurrencyLevel are
* nonpositive.
*/
public ConcurrentWeakHashMap(int initialCapacity,
float loadFactor, int concurrencyLevel) {
if (!(loadFactor > 0) || initialCapacity < 0 || concurrencyLevel <= 0)
throw new IllegalArgumentException();
if (concurrencyLevel > MAX_SEGMENTS)
concurrencyLevel = MAX_SEGMENTS;
// Find power-of-two sizes best matching arguments
int sshift = 0;
int ssize = 1;
while (ssize < concurrencyLevel) {
++sshift;
ssize <<= 1;
}
segmentShift = 32 - sshift;
segmentMask = ssize - 1;
this.segments = Segment.newArray(ssize);
if (initialCapacity > MAXIMUM_CAPACITY)
initialCapacity = MAXIMUM_CAPACITY;
int c = initialCapacity / ssize;View on GitHub (pinned to 744c3d3075)
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
Example fix
// before
int level = Integer.parseInt(props.getProperty("map.level")); // 0 when unset
map = new ConcurrentWeakHashMap(1024, 0.75f, level);
// after
int level = Math.max(1, Integer.parseInt(props.getProperty("map.level", "16")));
map = new ConcurrentWeakHashMap(Math.max(0, 1024), 0.75f, level); Defensive patterns
Strategy: validation
Validate before calling
static ConcurrentWeakHashMap<String,Object> safeCreate(int cap, float lf, int level) {
if (lf <= 0f || cap < 0 || level <= 0) throw new IllegalArgumentException("bad map args: cap=" + cap + " lf=" + lf + " level=" + level);
return new ConcurrentWeakHashMap<>(cap, lf, level);
} Try / catch
try { map = new ConcurrentWeakHashMap<>(cap, lf, level); } catch (IllegalArgumentException e) { map = new ConcurrentWeakHashMap<>(); } Prevention
- 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
When it happens
Trigger: new ConcurrentWeakHashMap(int initialCapacity, float loadFactor, int concurrencyLevel) called with loadFactor <= 0, initialCapacity < 0, or concurrencyLevel <= 0.
Common situations: 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.
Related errors
- Cannot find constructor with parameter types: ${constructorP
- negative cache size:${size}
- NullPointerException
- NoSuchElementException
- IllegalStateException
AI-assisted analysis of pinpoint-apm/pinpoint@744c3d3075 (2026-09-07).
Data as JSON: /api/errors/21932a9f47876272.
Report an issue: GitHub.