eclipse-vertx/vert.x · error · IllegalArgumentException

Given value:${value}. Expecting value >= 0.

Error message

Given value:${value}. Expecting value >= 0.

What it means

roundToPowerOfTwo also guards against negative input: a value below 0 has no power-of-two rounding and triggers IllegalArgumentException 'Given value:X. Expecting value >= 0.' This is a fail-fast precondition inside HybridJacksonPool's pooling helper.

Source

Thrown at vertx-core/src/main/java/io/vertx/core/json/jackson/HybridJacksonPool.java:207

      // multiplied by 2^32, which has the best possible scattering properties.
      int probe = (int) ((Thread.currentThread().getId() * 0x9e3779b9) & Integer.MAX_VALUE);
      // xorshift
      probe ^= probe << 13;
      probe ^= probe >>> 17;
      probe ^= probe << 5;
      return probe;
    }
  }

  private static final int MAX_POW2 = 1 << 30;

  private static int roundToPowerOfTwo(final int value) {
    if (value > MAX_POW2) {
      throw new IllegalArgumentException(
        "There is no larger power of 2 int for value:" + value + " since it exceeds 2^31.");
    }
    if (value < 0) {
      throw new IllegalArgumentException("Given value:" + value + ". Expecting value >= 0.");
    }
    final int nextPow2 = 1 << (32 - Integer.numberOfLeadingZeros(value - 1));
    return nextPow2;
  }
}

View on GitHub (pinned to fb308bd8c3)

Solutions

  1. Clamp to non-negative before construction: Math.max(0, value) (then ensure >= 1 for the pool)
  2. Fix the negative value in the size configuration or property source
  3. Add validation at the configuration-parsing boundary to reject negative sizes early

Example fix

// before
int stripes = configuredUsers - reserved; // can go negative
new StripedLockFreePool(stripes);
// after
int stripes = Math.max(1, configuredUsers - reserved);
new StripedLockFreePool(stripes);
Defensive patterns

Strategy: validation

Validate before calling

if (value < 0) throw new IllegalArgumentException("pool size must be >= 0");

Try / catch

try {
  pool = new HybridJacksonPool.StripedLockFreePool(rawSize);
} catch (IllegalArgumentException e) {
  pool = new HybridJacksonPool.StripedLockFreePool(16);
}

Prevention

When it happens

Trigger: Constructing StripedLockFreePool with a negative stripesCount — e.g. a size property parsed as a negative number, or arithmetic underflow (multiplication/subtraction) producing a negative pool size before the positive check ordering (the > MAX_POW2 check happens first).

Common situations: Config file with a negative pool size; computing stripes as users - overhead yielding a negative; parsing errors where '-1' sentinel leaks into configuration.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of eclipse-vertx/vert.x@fb308bd8c3 (2026-09-06). Data as JSON: /api/errors/89d2d7e5237a1514. Report an issue: GitHub.