{"record":{"id":"ef3daf24dd04eb22","repo":"apache/dubbo","slug":"threadfactory","errorCode":null,"errorMessage":"threadFactory","messagePattern":"threadFactory","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java","lineNumber":232,"sourceCode":"     *                           {@link TimerTask} execution.\n     * @param tickDuration       the duration between tick\n     * @param unit               the time unit of the {@code tickDuration}\n     * @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","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java#L214-L250","documentation":"NullPointerException thrown by the HashedWheelTimer constructor when the threadFactory parameter is null. HashedWheelTimer spawns a dedicated worker thread for ticking, so it requires a ThreadFactory to create that thread. This is a fail-fast validation at construction time — the parameter is mandatory and cannot be defaulted. Dubbo's HashedWheelTimer is a Netty-derived timing-wheel implementation used for timeout scheduling.","triggerScenarios":"Constructing a HashedWheelTimer with an explicit null threadFactory argument. Typically a programming error where the caller failed to supply or resolve the ThreadFactory before passing it.","commonSituations":"Custom code constructing HashedWheelTimer directly with a ThreadFactory variable that was never assigned; dependency injection misconfiguration that injects null for the ThreadFactory bean; conditional logic that yields null in an edge case.","solutions":["Pass a non-null ThreadFactory — use Executors.defaultThreadFactory() if you have no custom requirement.","If using dependency injection, verify the ThreadFactory bean is properly configured and not null.","Add a null check before construction and supply a default factory."],"exampleFix":"// before\nThreadFactory factory = possiblyNullFactory;\nnew HashedWheelTimer(factory, 100, TimeUnit.MILLISECONDS, 512);\n\n// after\nThreadFactory factory = possiblyNullFactory != null ? possiblyNullFactory : Executors.defaultThreadFactory();\nnew HashedWheelTimer(factory, 100, TimeUnit.MILLISECONDS, 512);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(threadFactory, \"threadFactory must not be null\");\n// or supply a default:\nThreadFactory factory = threadFactory != null ? threadFactory : Executors.defaultThreadFactory();\nnew HashedWheelTimer(factory, tickDuration, unit, ticksPerWheel);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass Executors.defaultThreadFactory() or a custom non-null factory.","Use Objects.requireNonNull() to fail with a clear message before reaching the constructor.","If injecting via DI, mark the dependency @Required or validate at bean post-construction."],"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"}