{"record":{"id":"b616fbe1b96c7615","repo":"pinpoint-apm/pinpoint","slug":"denominator-must-be-different-from-0","errorCode":null,"errorMessage":"denominator must be different from 0","messagePattern":"denominator must be different from 0","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"commons/src/main/java/com/navercorp/pinpoint/common/util/MathUtils.java","lineNumber":65,"sourceCode":"\n    // copy Apache commons-math 3.6.1 FastMath.floorMod(long, long)\n    /** Finds q such that a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0.\n     * <p>\n     * This methods returns the same value as integer division when\n     * a and b are same signs, but returns a different value when\n     * they are opposite (i.e. q is negative).\n     * </p>\n     * @param a dividend\n     * @param b divisor\n     * @return q such that a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0\n     * @exception IllegalArgumentException if b == 0\n     * @see #floorMod(long, long)\n     * @since 3.4\n     */\n    public static long floorMod(final long a, final long b) {\n\n        if (b == 0L) {\n            throw new IllegalArgumentException(\"denominator must be different from 0\");\n        }\n\n        final long m = a % b;\n        if ((a ^ b) >= 0L || m == 0L) {\n            // a an b have same sign, or division is exact\n            return m;\n        } else {\n            // a and b have opposite signs and division is not exact\n            return b + m;\n        }\n\n    }\n\n    // copy Apache commons-math 3.6.1 FastMath.floorMod(int, int)\n    /** Finds r such that a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0.\n     * <p>\n     * This methods returns the same value as integer modulo when\n     * a and b are same signs, but returns a different value when","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/pinpoint-apm/pinpoint/blob/744c3d3075e595656abb1ae331ad2c0e4c9eb996/commons/src/main/java/com/navercorp/pinpoint/common/util/MathUtils.java#L47-L83","documentation":"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.","triggerScenarios":"Calling floorMod(a, 0L) — e.g. a bucket count, shard count, or modulus computed from empty collections or zeroed config.","commonSituations":"Distributing items across N buckets where N is 0 because a list was empty or a config key defaulted to 0.","solutions":["Ensure the denominator is a positive divisor before calling","Check size/config != 0 and use a safe default (e.g. 1)","Reject the zero value at the point where the modulus is computed"],"exampleFix":"// before\nlong m = MathUtils.floorMod(a, b); // b = 0\n// after\nif (b != 0) {\n    long m = MathUtils.floorMod(a, b);\n}","handlingStrategy":"validation","validationCode":"if (b == 0L) throw new IllegalArgumentException(\"denominator must not be 0\");\nlong m = MathUtils.floorMod(a, b);","typeGuard":null,"tryCatchPattern":"try {\n    m = MathUtils.floorMod(a, b);\n} catch (IllegalArgumentException e) {\n    logger.warn(\"floorMod denominator is 0\");\n    m = 0L;\n}","preventionTips":["Ensure bucket/shard counts are computed from non-empty collections","Use size fallback (e.g. 1) when a list can be empty","Validate modulus config != 0 at startup"],"tags":["math","division-by-zero","argument-check"],"backgroundTag":"invalid-argument-value","analyzedSha":"744c3d3075e595656abb1ae331ad2c0e4c9eb996","analyzedAt":"2026-09-07T18:48:45.289Z","contentChangedAt":"2026-09-07T18:48:45.289Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}