pinpoint-apm/pinpoint · error · IllegalArgumentException

denominator must be different from 0

Error message

denominator must be different from 0

What it means

MathUtils.floorMod(long a, long b) computes a floor-style modulo. A zero denominator would cause ArithmeticException (/ by zero) in the underlying % operation, so the library pre-checks and throws IllegalArgumentException with a clear message instead.

Solutions

  1. Ensure the denominator is a positive divisor before calling
  2. Check size/config != 0 and use a safe default (e.g. 1)
  3. Reject the zero value at the point where the modulus is computed

Example fix

// before
long m = MathUtils.floorMod(a, b); // b = 0
// after
if (b != 0) {
    long m = MathUtils.floorMod(a, b);
}
Defensive patterns

Strategy: validation

Validate before calling

if (b == 0L) throw new IllegalArgumentException("denominator must not be 0");
long m = MathUtils.floorMod(a, b);

Try / catch

try {
    m = MathUtils.floorMod(a, b);
} catch (IllegalArgumentException e) {
    logger.warn("floorMod denominator is 0");
    m = 0L;
}

Prevention

When it happens

Trigger: Calling floorMod(a, 0L) — e.g. a bucket count, shard count, or modulus computed from empty collections or zeroed config.

Common situations: Distributing items across N buckets where N is 0 because a list was empty or a config key defaulted to 0.

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 pinpoint-apm/pinpoint@744c3d3075 (2026-09-07). Data as JSON: /api/errors/b616fbe1b96c7615. Report an issue: GitHub.

Appendix: source

Thrown at commons/src/main/java/com/navercorp/pinpoint/common/util/MathUtils.java:65

    // copy Apache commons-math 3.6.1 FastMath.floorMod(long, long)
    /** Finds q such that a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0.
     * <p>
     * This methods returns the same value as integer division when
     * a and b are same signs, but returns a different value when
     * they are opposite (i.e. q is negative).
     * </p>
     * @param a dividend
     * @param b divisor
     * @return q such that a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0
     * @exception IllegalArgumentException if b == 0
     * @see #floorMod(long, long)
     * @since 3.4
     */
    public static long floorMod(final long a, final long b) {

        if (b == 0L) {
            throw new IllegalArgumentException("denominator must be different from 0");
        }

        final long m = a % b;
        if ((a ^ b) >= 0L || m == 0L) {
            // a an b have same sign, or division is exact
            return m;
        } else {
            // a and b have opposite signs and division is not exact
            return b + m;
        }

    }

    // copy Apache commons-math 3.6.1 FastMath.floorMod(int, int)
    /** Finds r such that a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0.
     * <p>
     * This methods returns the same value as integer modulo when
     * a and b are same signs, but returns a different value when

View on GitHub (pinned to 744c3d3075)