{"record":{"id":"5a6ac3ce3aa33f73","repo":"apache/pulsar","slug":"need-to-specify-either-enable-delete-while-inactiv-5a6ac3","errorCode":null,"errorMessage":"Need to specify either enable-delete-while-inactive or disable-delete-while-inactive","messagePattern":"Need to specify either enable-delete-while-inactive or disable-delete-while-inactive","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java","lineNumber":2814,"sourceCode":"\n        @Option(names = { \"--disable-delete-while-inactive\", \"-d\" }, description = \"Disable delete while inactive\")\n        private boolean disableDeleteWhileInactive = false;\n\n        @Option(names = {\"--max-inactive-duration\", \"-t\"}, description = \"Max duration of topic inactivity \"\n                + \"in seconds, topics that are inactive for longer than this value will be deleted \"\n                + \"(eg: 1s, 10s, 1m, 5h, 3d)\", required = true,\n                converter = TimeUnitToSecondsConverter.class)\n        private Long maxInactiveDurationInSeconds;\n\n        @Option(names = { \"--delete-mode\", \"-m\" }, description = \"Mode of delete inactive topic, Valid options are: \"\n                + \"[delete_when_no_subscriptions, delete_when_subscriptions_caught_up]\", required = true)\n        private String inactiveTopicDeleteMode;\n\n        @Override\n        void run() throws PulsarAdminException {\n            String persistentTopic = validatePersistentTopic(topicName);\n            if (enableDeleteWhileInactive == disableDeleteWhileInactive) {\n                throw new IllegalArgumentException(\"Need to specify either enable-delete-while-inactive \"\n                        + \"or disable-delete-while-inactive\");\n            }\n            InactiveTopicDeleteMode deleteMode = null;\n            try {\n                deleteMode = InactiveTopicDeleteMode.valueOf(inactiveTopicDeleteMode);\n            } catch (IllegalArgumentException e) {\n                throw new ParameterException(\"delete mode can only be set to delete_when_no_subscriptions \"\n                        + \"or delete_when_subscriptions_caught_up\");\n            }\n            getTopics().setInactiveTopicPolicies(persistentTopic, new InactiveTopicPolicies(deleteMode,\n                    maxInactiveDurationInSeconds.intValue(), enableDeleteWhileInactive));\n        }\n    }\n\n    @Command(description = \"Remove inactive topic policies from a topic\", hidden = true)\n    private class RemoveInactiveTopicPolicies extends CliCommand {\n        @Parameters(description = \"persistent://tenant/namespace/topic\", arity = \"1\")\n        private String topicName;","sourceCodeStart":2796,"sourceCodeEnd":2832,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java#L2796-L2832","documentation":"The SetInactiveTopicPolicies command requires exactly one of the enable/disable flags for delete-while-inactive. When enableDeleteWhileInactive equals disableDeleteWhileInactive (both set or neither set), it throws IllegalArgumentException before parsing the delete mode or calling setInactiveTopicPolicies.","triggerScenarios":"Running `pulsar-admin topics set-inactive-topic-policies <topic> ...` with neither enable-delete-while-inactive nor disable-delete-while-inactive, or with both.","commonSituations":"Long flag names being truncated or typo'd in scripts; assuming other policy parameters alone are sufficient; copying only part of an example command.","solutions":["Add exactly one of --enable-delete-while-inactive or --disable-delete-while-inactive.","Verify the full command includes all required flags (delete mode and max-inactive-duration) in one invocation.","Check the current policies with the corresponding get command before modifying."],"exampleFix":"// before\nbin/pulsar-admin topics set-inactive-topic-policies my-topic --delete-mode delete_when_subscriptions_caught_up\n// after\nbin/pulsar-admin topics set-inactive-topic-policies my-topic --delete-mode delete_when_subscriptions_caught_up --enable-delete-while-inactive","handlingStrategy":"validation","validationCode":"// shell validation before invoking\ncase \"$MODE_FLAG\" in\n  --enable-delete-while-inactive|--disable-delete-while-inactive) ;;\n  *) echo \"must pass exactly one delete-while-inactive flag\"; exit 1;;\nesac","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include exactly one of the long-form enable/disable flags.","Copy full example commands rather than partial flags.","Fail fast on empty flag variables in automation."],"tags":["cli","argument-validation","pulsar-admin"],"backgroundTag":"missing-required-cli-flag","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}