{"record":{"id":"ec6ab9a83d142c85","repo":"apache/dubbo","slug":"unit","errorCode":null,"errorMessage":"unit","messagePattern":"unit","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java","lineNumber":235,"sourceCode":"     * @param ticksPerWheel      the size of the wheel\n     * @param maxPendingTimeouts The maximum number of pending timeouts after which call to\n     *                           {@code newTimeout} will result in\n     *                           {@link java.util.concurrent.RejectedExecutionException}\n     *                           being thrown. No maximum pending timeouts limit is assumed if\n     *                           this value is 0 or negative.\n     * @throws NullPointerException     if either of {@code threadFactory} and {@code unit} is {@code null}\n     * @throws IllegalArgumentException if either of {@code tickDuration} and {@code ticksPerWheel} is &lt;= 0\n     */\n    public HashedWheelTimer(\n        ThreadFactory threadFactory,\n        long tickDuration, TimeUnit unit, int ticksPerWheel,\n        long maxPendingTimeouts) {\n\n        if (threadFactory == null) {\n            throw new NullPointerException(\"threadFactory\");\n        }\n        if (unit == null) {\n            throw new NullPointerException(\"unit\");\n        }\n        if (tickDuration <= 0) {\n            throw new IllegalArgumentException(\"tickDuration must be greater than 0: \" + tickDuration);\n        }\n        if (ticksPerWheel <= 0) {\n            throw new IllegalArgumentException(\"ticksPerWheel must be greater than 0: \" + ticksPerWheel);\n        }\n\n        // Normalize ticksPerWheel to power of two and initialize the wheel.\n        wheel = createWheel(ticksPerWheel);\n        mask = wheel.length - 1;\n\n        // Convert tickDuration to nanos.\n        this.tickDuration = unit.toNanos(tickDuration);\n\n        // Prevent overflow.\n        if (this.tickDuration >= Long.MAX_VALUE / wheel.length) {\n            throw new IllegalArgumentException(String.format(","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java#L217-L253","documentation":"NullPointerException thrown by the HashedWheelTimer constructor when the unit (TimeUnit) parameter is null. The tick duration is meaningless without a unit, and the constructor converts tickDuration to nanoseconds via unit.toNanos(), so a null unit would cause an NPE later anyway. The constructor fails fast with a clear message instead. TimeUnit is mandatory for any time-based configuration.","triggerScenarios":"Constructing a HashedWheelTimer with a null TimeUnit argument for the tickDuration parameter. A straightforward programming error of passing null where a TimeUnit enum value is required.","commonSituations":"Calling code that derives the TimeUnit from configuration or a variable that resolved to null; misconfigured properties mapping that fails to parse a time unit string into a TimeUnit enum.","solutions":["Always pass an explicit TimeUnit constant (e.g., TimeUnit.MILLISECONDS) — never a potentially-null variable.","If deriving from configuration, validate and default the parsed TimeUnit before passing it to the constructor.","Use the convenience constructors (e.g., HashedWheelTimer(tickDuration, unit)) that reduce the number of mandatory parameters."],"exampleFix":"// before\nTimeUnit unit = parseUnit(config); // may return null\nnew HashedWheelTimer(factory, 100, unit, 512);\n\n// after\nTimeUnit unit = parseUnit(config);\nif (unit == null) unit = TimeUnit.MILLISECONDS;\nnew HashedWheelTimer(factory, 100, unit, 512);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(unit, \"unit must not be null\");\nTimeUnit safeUnit = unit != null ? unit : TimeUnit.MILLISECONDS;\nnew HashedWheelTimer(threadFactory, tickDuration, safeUnit, ticksPerWheel);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass an explicit TimeUnit constant (MILLISECONDS, SECONDS, etc.).","Default to TimeUnit.MILLISECONDS when parsing configuration if the unit is missing.","Use Objects.requireNonNull() to catch null early with a descriptive message."],"tags":["timer","null-check","constructor","configuration"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}