{"record":{"id":"258e58dde260d22f","repo":"apache/pulsar","slug":"option-version-must-be-greater-than-0-but-found","errorCode":null,"errorMessage":"Option --version must be greater than 0, but found %d","messagePattern":"Option --version must be greater than 0, but found (.+?)","errorType":"validation","errorClass":"ParameterException","httpStatus":null,"severity":"error","filePath":"pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdSchemas.java","lineNumber":72,"sourceCode":"        private String topicName;\n\n        @Option(names = {\"-v\", \"--version\"}, description = \"version\", required = false)\n        private Long version;\n\n        @Option(names = {\"-a\", \"--all-version\"}, description = \"all version\", required = false)\n        private boolean all = false;\n\n        @Override\n        void run() throws Exception {\n            String topic = validateTopicName(topicName);\n            if (version != null && all) {\n                throw new ParameterException(\"Only one or neither of --version and --all-version can be specified.\");\n            }\n            if (version == null && !all) {\n                System.out.println(getAdmin().schemas().getSchemaInfoWithVersion(topic));\n            } else if (!all) {\n                if (version < 0) {\n                    throw new ParameterException(\"Option --version must be greater than 0, but found \" + version);\n                }\n                System.out.println(getAdmin().schemas().getSchemaInfo(topic, version));\n            } else {\n                print(getAdmin().schemas().getAllSchemas(topic));\n            }\n        }\n    }\n\n    @Command(description = \"Get the schema for a topic\")\n    private class GetSchemaMetadata extends CliCommand {\n        @Parameters(description = \"persistent://tenant/namespace/topic\", arity = \"1\")\n        private String topicName;\n\n        @Override\n        void run() throws Exception {\n            String topic = validateTopicName(topicName);\n            print(getAdmin().schemas().getSchemaMetadata(topic));\n        }","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdSchemas.java#L54-L90","documentation":"When using `pulsar-admin schemas get --version`, the version must be non-negative; a negative value is rejected with this ParameterException. Note the message says 'greater than 0' while the check is version < 0, so 0 itself is accepted.","triggerScenarios":"Running schemas get with --version -1 or any negative number, often from a variable initialized to -1 as a sentinel.","commonSituations":"Scripts using -1 to mean 'latest' (which is the behavior when the flag is omitted, not when set negative); arithmetic producing negative versions; copying conventions from client APIs where -1 means latest.","solutions":["Omit --version to fetch the latest schema instead of passing a negative version","Pass a valid non-negative version number obtained from schema version info","Fix the script sentinel: use absence of the flag for 'latest' rather than -1"],"exampleFix":"// before\npulsar-admin schemas get --topic t --version -1\n// after\npulsar-admin schemas get --topic t   # latest\n# or\npulsar-admin schemas get --topic t --version 0","handlingStrategy":"validation","validationCode":"if (version != null && version < 0) {\n    throw new IllegalArgumentException(\"Schema version must be >= 0\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    SchemaInfo info = admin.schemas().getSchemaInfo(topic, version);\n} catch (org.apache.pulsar.client.admin.PulsarAdminException e) {\n    // fall back to latest schema\n}","preventionTips":["Use omission of --version (not -1) to mean latest","Clamp or validate version numbers from scripts before passing them","Fetch valid versions via get-all-schemas or version info first"],"tags":["cli","schema","validation"],"backgroundTag":"invalid-parameter-value","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"}