apache/pulsar · error · IllegalArgumentException

Need to specify either enable-delete-while-inactive or disab

Error message

Need to specify either enable-delete-while-inactive or disable-delete-while-inactive

What it means

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.

Source

Thrown at pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java:2814

        @Option(names = { "--disable-delete-while-inactive", "-d" }, description = "Disable delete while inactive")
        private boolean disableDeleteWhileInactive = false;

        @Option(names = {"--max-inactive-duration", "-t"}, description = "Max duration of topic inactivity "
                + "in seconds, topics that are inactive for longer than this value will be deleted "
                + "(eg: 1s, 10s, 1m, 5h, 3d)", required = true,
                converter = TimeUnitToSecondsConverter.class)
        private Long maxInactiveDurationInSeconds;

        @Option(names = { "--delete-mode", "-m" }, description = "Mode of delete inactive topic, Valid options are: "
                + "[delete_when_no_subscriptions, delete_when_subscriptions_caught_up]", required = true)
        private String inactiveTopicDeleteMode;

        @Override
        void run() throws PulsarAdminException {
            String persistentTopic = validatePersistentTopic(topicName);
            if (enableDeleteWhileInactive == disableDeleteWhileInactive) {
                throw new IllegalArgumentException("Need to specify either enable-delete-while-inactive "
                        + "or disable-delete-while-inactive");
            }
            InactiveTopicDeleteMode deleteMode = null;
            try {
                deleteMode = InactiveTopicDeleteMode.valueOf(inactiveTopicDeleteMode);
            } catch (IllegalArgumentException e) {
                throw new ParameterException("delete mode can only be set to delete_when_no_subscriptions "
                        + "or delete_when_subscriptions_caught_up");
            }
            getTopics().setInactiveTopicPolicies(persistentTopic, new InactiveTopicPolicies(deleteMode,
                    maxInactiveDurationInSeconds.intValue(), enableDeleteWhileInactive));
        }
    }

    @Command(description = "Remove inactive topic policies from a topic", hidden = true)
    private class RemoveInactiveTopicPolicies extends CliCommand {
        @Parameters(description = "persistent://tenant/namespace/topic", arity = "1")
        private String topicName;

View on GitHub (pinned to 820761864e)

Solutions

  1. Add exactly one of --enable-delete-while-inactive or --disable-delete-while-inactive.
  2. Verify the full command includes all required flags (delete mode and max-inactive-duration) in one invocation.
  3. Check the current policies with the corresponding get command before modifying.

Example fix

// before
bin/pulsar-admin topics set-inactive-topic-policies my-topic --delete-mode delete_when_subscriptions_caught_up
// after
bin/pulsar-admin topics set-inactive-topic-policies my-topic --delete-mode delete_when_subscriptions_caught_up --enable-delete-while-inactive
Defensive patterns

Strategy: validation

Validate before calling

// shell validation before invoking
case "$MODE_FLAG" in
  --enable-delete-while-inactive|--disable-delete-while-inactive) ;;
  *) echo "must pass exactly one delete-while-inactive flag"; exit 1;;
esac

Prevention

When it happens

Trigger: Running `pulsar-admin topics set-inactive-topic-policies <topic> ...` with neither enable-delete-while-inactive nor disable-delete-while-inactive, or with both.

Common situations: Long flag names being truncated or typo'd in scripts; assuming other policy parameters alone are sufficient; copying only part of an example command.

Related errors


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/5a6ac3ce3aa33f73. Report an issue: GitHub.