apache/pulsar · error · ParameterException

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 set-inactive-topic-policies command requires an explicit direction for the delete-while-inactive feature: exactly one of --enable-delete-while-inactive or --disable-delete-while-inactive must be given. Because both flags default to false, passing neither (or somehow both) makes them equal and triggers this ParameterException.

Source

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

        @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;

        @Option(names = { "--global", "-g" }, description = "Whether to set this policy globally. "
                + "If set to true, the policy will be replicate to other clusters asynchronously")
        private boolean isGlobal = false;

        @Override
        void run() throws PulsarAdminException {
            String persistentTopic = validatePersistentTopic(topicName);
            if (enableDeleteWhileInactive == disableDeleteWhileInactive) {
                throw new ParameterException("Need to specify either enable-delete-while-inactive or "
                        + "disable-delete-while-inactive");
            }
            InactiveTopicDeleteMode deleteMode;
            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");
            }
            getTopicPolicies(isGlobal).setInactiveTopicPolicies(persistentTopic, new InactiveTopicPolicies(deleteMode,
                    maxInactiveDurationInSeconds.intValue(), enableDeleteWhileInactive));
        }
    }

    @Command(description = "Remove inactive topic policies from a topic")
    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 to the command
  2. If you only want to change maxInactiveDurationInSeconds, still pass the flag matching the current desired enabled/disabled state

Example fix

// before
pulsar-admin topics set-inactive-topic-policies my-topic --delete-mode delete_when_no_subscriptions --max-inactive-duration 3600
// after
pulsar-admin topics set-inactive-topic-policies my-topic --delete-mode delete_when_no_subscriptions --max-inactive-duration 3600 --enable-delete-while-inactive
Defensive patterns

Strategy: validation

Validate before calling

boolean enable = flags.contains("--enable-delete-while-inactive");
boolean disable = flags.contains("--disable-delete-while-inactive");
if (enable == disable) throw new IllegalArgumentException("pass exactly one of enable/disable-delete-while-inactive");

Prevention

When it happens

Trigger: Running set-inactive-topic-policies without either the enable or disable flag, or (if flags are set as exclusive booleans) passing both enable and disable together so enableDeleteWhileInactive == disableDeleteWhileInactive evaluates true.

Common situations: Scripts omitting the flag because an older CLI version did not require it; users assuming the command only updates maxInactiveDurationInSeconds and leaves the enabled state untouched; template scripts with placeholder flags never filled in.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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