{"record":{"id":"d3ddfe517f7d83fc","repo":"apache/pulsar","slug":"not-support-to-set-executeexistingdelayedtasksafte","errorCode":null,"errorMessage":"Not support to set executeExistingDelayedTasksAfterShutdownPolicy, it is always false","messagePattern":"Not support to set executeExistingDelayedTasksAfterShutdownPolicy, it is always false","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/common/util/SingleThreadNonConcurrentFixedRateScheduler.java","lineNumber":216,"sourceCode":"    public void setContinueExistingPeriodicTasksAfterShutdownPolicy(boolean flag) {\n        throw new IllegalArgumentException(\"Not support to set continueExistingPeriodicTasksAfterShutdownPolicy, it is\"\n                + \" always false\");\n    }\n\n    /**\n     * {@inheritDoc}\n     */\n    @Override\n    public boolean getContinueExistingPeriodicTasksAfterShutdownPolicy() {\n        return false;\n    }\n\n    /**\n     * {@inheritDoc}\n     */\n    @Override\n    public void setExecuteExistingDelayedTasksAfterShutdownPolicy(boolean flag) {\n        throw new IllegalArgumentException(\"Not support to set executeExistingDelayedTasksAfterShutdownPolicy, it is\"\n                + \" always false\");\n    }\n\n    /**\n     * {@inheritDoc}\n     */\n    @Override\n    public boolean getExecuteExistingDelayedTasksAfterShutdownPolicy() {\n        return false;\n    }\n\n    /**\n     * {@inheritDoc}\n     * Since the method \"remove(runnable)\" of DelayedWorkQueue is expensive if the tasks in the queue is not the same\n     * type, we denied the remove policy.\n     */\n    @Override\n    public void setRemoveOnCancelPolicy(boolean value) {","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/common/util/SingleThreadNonConcurrentFixedRateScheduler.java#L198-L234","documentation":"SingleThreadNonConcurrentFixedRateScheduler always behaves as if executeExistingDelayedTasksAfterShutdownPolicy is false: delayed tasks are never executed after shutdown. The setExecuteExistingDelayedTasksAfterShutdownPolicy method therefore unconditionally throws IllegalArgumentException, rejecting any attempt to change this fixed policy.","triggerScenarios":"Calling setExecuteExistingDelayedTasksAfterShutdownPolicy(true or false) on a SingleThreadNonConcurrentFixedRateScheduler, usually from generic ScheduledExecutorService configuration code that applies policy tuning to any scheduler it manages.","commonSituations":"Copied executor-tuning code (from ScheduledThreadPoolExecutor usage) applied to this custom scheduler; frameworks that centrally configure executors for an application that also instantiates Pulsar's scheduler; migration from java.util.concurrent schedulers.","solutions":["Remove the call; the scheduler intentionally discards delayed tasks after shutdown.","Guard the call so it is only applied to schedulers that support the policy.","If delayed tasks must survive shutdown, use ScheduledThreadPoolExecutor or redesign shutdown handling (cancel tasks explicitly and reschedule on a new executor).","Catch IllegalArgumentException if the configuration path must remain compatible with arbitrary executor types."],"exampleFix":"// before\nscheduler.setExecuteExistingDelayedTasksAfterShutdownPolicy(true);\n// after\nif (scheduler instanceof java.util.concurrent.ScheduledThreadPoolExecutor) {\n    ((java.util.concurrent.ScheduledThreadPoolExecutor) scheduler).setExecuteExistingDelayedTasksAfterShutdownPolicy(true);\n}","handlingStrategy":"try-catch","validationCode":"static boolean supportsShutdownPolicies(java.util.concurrent.ScheduledExecutorService s) {\n    return !(s instanceof org.apache.pulsar.common.util.SingleThreadNonConcurrentFixedRateScheduler);\n}","typeGuard":"static boolean isPolicyConfigurable(java.util.concurrent.ScheduledExecutorService s) {\n    return s instanceof java.util.concurrent.ScheduledThreadPoolExecutor;\n}","tryCatchPattern":"try {\n    scheduler.setExecuteExistingDelayedTasksAfterShutdownPolicy(flag);\n} catch (IllegalArgumentException e) {\n    LOG.info(\"Scheduler {} does not support delayed-task shutdown policy: {}\", scheduler, e.getMessage());\n}","preventionTips":["Never call setExecuteExistingDelayedTasksAfterShutdownPolicy on this scheduler — delayed tasks are always discarded after shutdown","Apply policy setters only to ScheduledThreadPoolExecutor instances","Redesign shutdown handling if delayed tasks must survive shutdown (explicit cancel/reschedule)","Catch IllegalArgumentException in configuration code shared across executor types"],"tags":["pulsar","scheduler","unsupported-operation","shutdown-policy"],"backgroundTag":"unsupported-scheduler-policy","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}