apache/pulsar · error · ParameterException

Need to specify either --enable or --disable

Error message

Need to specify either --enable or --disable

What it means

Thrown by the set-deduplication-status command when neither or both of --enable and --disable were specified. The pair must be mutually exclusive and exactly one must be present; `enable == disable` catches the ambiguous case (both false or both true) before calling setDeduplicationStatus.

Source

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

    }

    @Command(description = "Enable or disable deduplication for a namespace")
    private class SetDeduplication extends CliCommand {
        @Parameters(description = "tenant/namespace", arity = "1")
        private String namespaceName;

        @Option(names = { "--enable", "-e" }, description = "Enable deduplication")
        private boolean enable = false;

        @Option(names = { "--disable", "-d" }, description = "Disable deduplication")
        private boolean disable = false;

        @Override
        void run() throws PulsarAdminException {
            String namespace = validateNamespace(namespaceName);

            if (enable == disable) {
                throw new ParameterException("Need to specify either --enable or --disable");
            }
            getAdmin().namespaces().setDeduplicationStatus(namespace, enable);
        }
    }

    @Command(description = "Enable or disable autoTopicCreation for a namespace, overriding broker settings")
    private class SetAutoTopicCreation extends CliCommand {
        @Parameters(description = "tenant/namespace", arity = "1")
        private String namespaceName;

        @Option(names = { "--enable", "-e" }, description = "Enable allowAutoTopicCreation on namespace")
        private boolean enable = false;

        @Option(names = { "--disable", "-d" }, description = "Disable allowAutoTopicCreation on namespace")
        private boolean disable = false;

        @Option(names = { "--type", "-t" }, description = "Type of topic to be auto-created. "
                + "Possible values: (partitioned, non-partitioned). Default value: non-partitioned")

View on GitHub (pinned to 820761864e)

Solutions

  1. Pass exactly one flag: --enable to turn deduplication on, --disable to turn it off
  2. Remove any duplicate/contradictory flag in the scripted command line
  3. Check templated commands so only one of the two flags is rendered
  4. Run with --help to confirm the flag names for your CLI version

Example fix

// before
pulsar-admin namespaces set-deduplication my-tenant/ns
// after
pulsar-admin namespaces set-deduplication my-tenant/ns --enable
Defensive patterns

Strategy: validation

Validate before calling

count=0; [[ $ENABLE == true ]] && count=$((count+1)); [[ $DISABLE == true ]] && count=$((count+1))
[ $count -eq 1 ] || { echo "specify exactly one of --enable/--disable"; exit 1; }

Try / catch

try { ... } catch (ParameterException e) { /* ambiguous flags: pass exactly one of --enable/--disable */ }

Prevention

When it happens

Trigger: Running `pulsar-admin namespaces set-deduplication <ns>` with neither flag, with both flags, or with both flags defaulting to false because the command uses JCommander boolean flags whose defaults make them equal.

Common situations: Forgetting the flag entirely in a script; templating that injects both flags; assuming a positional on/off argument instead of a flag; older CLI examples using a different flag name.

Understand the failure class

Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.

Related errors


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