pinpoint-apm/pinpoint · error · IllegalArgumentException

Illegal Capacity: +initialCapacity

Error message

Illegal Capacity: +initialCapacity

What it means

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.

Solutions

  1. Pass a non-negative capacity; clamp with Math.max(0, size)
  2. Validate any capacity config value at load time
  3. Use the no-arg constructor if the size is unknown

Example fix

// before
IntHashMap map = new IntHashMap(size, 0.75f); // size = -10
// after
IntHashMap map = new IntHashMap(Math.max(0, size), 0.75f);
Defensive patterns

Strategy: validation

Validate before calling

if (initialCapacity < 0) throw new IllegalArgumentException("initialCapacity must be >= 0");
IntHashMap map = new IntHashMap(initialCapacity, 0.75f);

Try / catch

try {
    map = new IntHashMap(initialCapacity, loadFactor);
} catch (IllegalArgumentException e) {
    logger.warn("IntHashMap capacity invalid: {}", e.getMessage());
    map = new IntHashMap();
}

Prevention

When it happens

Trigger: Constructing IntHashMap with a negative initialCapacity, e.g. from a computed size, a negative cache-size config, or a subtraction that underflowed.

Common situations: Sizing the map from (expected - buffer) where buffer exceeded expected; misconfigured capacity property parsed as negative.

Related errors


AI-assisted analysis of pinpoint-apm/pinpoint@744c3d3075 (2026-09-07). Data as JSON: /api/errors/4b9149da1faa538a. Report an issue: GitHub.

Appendix: source

Thrown at commons/src/main/java/com/navercorp/pinpoint/common/util/apache/IntHashMap.java:123

     *   than zero.
     */
    public IntHashMap(int initialCapacity) {
        this(initialCapacity, 0.75f);
    }

    /**
     * <p>Constructs a new, empty hashtable with the specified initial
     * capacity and the specified load factor.</p>
     *
     * @param initialCapacity the initial capacity of the hashtable.
     * @param loadFactor the load factor of the hashtable.
     * @throws IllegalArgumentException  if the initial capacity is less
     *             than zero, or if the load factor is nonpositive.
     */
    public IntHashMap(int initialCapacity, float loadFactor) {
        super();
        if (initialCapacity < 0) {
            throw new IllegalArgumentException("Illegal Capacity: " + initialCapacity);
        }
        if (loadFactor <= 0) {
            throw new IllegalArgumentException("Illegal Load: " + loadFactor);
        }
        if (initialCapacity == 0) {
            initialCapacity = 1;
        }

        this.loadFactor = loadFactor;
        table = new Entry[initialCapacity];
        threshold = (int) (initialCapacity * loadFactor);
    }

    /**
     * <p>Returns the number of keys in this hashtable.</p>
     *
     * @return  the number of keys in this hashtable.
     */

View on GitHub (pinned to 744c3d3075)