{"record":{"id":"07df233dc560c3da","repo":"pinpoint-apm/pinpoint","slug":"cannot-round-to-nearest-multiple-of-values-less-th","errorCode":null,"errorMessage":"cannot round to nearest multiple of values less than 1","messagePattern":"cannot round to nearest multiple of values less than 1","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"commons/src/main/java/com/navercorp/pinpoint/common/util/MathUtils.java","lineNumber":35,"sourceCode":"package com.navercorp.pinpoint.common.util;\n\n/**\n * @author emeroad\n */\npublic final class MathUtils {\n    private MathUtils() {\n    }\n\n    public static int fastAbs(final int value) {\n        return value & Integer.MAX_VALUE;\n    }\n\n    public static long roundToNearestMultipleOf(final long num, final long multipleOf) {\n        if (num < 0) {\n            throw new IllegalArgumentException(\"num cannot be negative\");\n        }\n        if (multipleOf < 1) {\n            throw new IllegalArgumentException(\"cannot round to nearest multiple of values less than 1\");\n        }\n        if (num < multipleOf) {\n            return multipleOf;\n        }\n        if ((num % multipleOf) >= (multipleOf / 2.0)) {\n            return (num + multipleOf) - (num % multipleOf);\n        } else {\n            return num - (num % multipleOf);\n        }\n    }\n\n\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).","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/pinpoint-apm/pinpoint/blob/744c3d3075e595656abb1ae331ad2c0e4c9eb996/commons/src/main/java/com/navercorp/pinpoint/common/util/MathUtils.java#L17-L53","documentation":"MathUtils.roundToNearestMultipleOf requires the multipleOf argument to be at least 1; zero, negative, or fractional-less values would cause division by zero or undefined rounding. The library throws IllegalArgumentException to signal the misuse.","triggerScenarios":"Calling roundToNearestMultipleOf(num, multipleOf) with multipleOf < 1, typically 0 from an unset config or a negative interval value.","commonSituations":"A rounding interval configured as 0 because the property was missing; a computed step size of 0 from an empty aggregation.","solutions":["Ensure the rounding interval is a positive constant (>= 1) before calling","Validate config: reject interval <= 0 at startup","Guard the call site with a fallback default like 1"],"exampleFix":"// before\nlong rounded = MathUtils.roundToNearestMultipleOf(num, interval); // interval = 0\n// after\nlong step = interval >= 1 ? interval : 1;\nlong rounded = MathUtils.roundToNearestMultipleOf(num, step);","handlingStrategy":"validation","validationCode":"if (multipleOf < 1) throw new IllegalArgumentException(\"multipleOf must be >= 1: \" + multipleOf);\nlong rounded = MathUtils.roundToNearestMultipleOf(num, multipleOf);","typeGuard":null,"tryCatchPattern":"try {\n    rounded = MathUtils.roundToNearestMultipleOf(num, multipleOf);\n} catch (IllegalArgumentException e) {\n    logger.warn(\"invalid multipleOf: {}\", e.getMessage());\n    rounded = num;\n}","preventionTips":["Default interval configs to a positive value, never 0","Reject interval <= 0 at configuration load time","Guard computed step sizes against zero"],"tags":["math","argument-check","pinpoint-commons"],"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"}