{"record":{"id":"18658f4f6d4bd81a","repo":"apache/pulsar","slug":"end-timestamp-should-be-positive","errorCode":null,"errorMessage":"end timestamp should be positive.","messagePattern":"end timestamp should be positive\\.","errorType":"validation","errorClass":"CommandLine.ParameterException","httpStatus":null,"severity":"error","filePath":"pulsar-client-tools/src/main/java/org/apache/pulsar/client/cli/CmdConsume.java","lineNumber":167,"sourceCode":"\n    @Spec\n    private CommandSpec commandSpec;\n\n    /**\n     * Run the consume command.\n     *\n     * @return 0 for success, < 0 otherwise\n     */\n    public int run() throws IOException {\n        if (this.subscriptionName == null || this.subscriptionName.isEmpty()) {\n            throw new CommandLine.ParameterException(commandSpec.commandLine(), \"Subscription name is not provided.\");\n        }\n        if (this.numMessagesToConsume < 0) {\n            throw new CommandLine.ParameterException(commandSpec.commandLine(),\n                    \"Number of messages should be zero or positive.\");\n        }\n        if (this.endTimestamp < 0) {\n            throw new CommandLine.ParameterException(commandSpec.commandLine(),\n                    \"end timestamp should be positive.\");\n        }\n\n        if (this.serviceURL.startsWith(\"ws\")) {\n            return consumeFromWebSocket(topic);\n        } else {\n            return consume(topic);\n        }\n    }\n\n    private int consume(String topic) {\n        int numMessagesConsumed = 0;\n        int returnCode = 0;\n\n        final Schema<?> schema;\n        if (\"auto_consume\".equals(schemaType)) {\n            schema = Schema.autoConsume();\n        } else if (\"bytes\".equals(schemaType)) {","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-tools/src/main/java/org/apache/pulsar/client/cli/CmdConsume.java#L149-L185","documentation":"CmdConsume.run validates endTimestamp and throws a CommandLine.ParameterException when it is negative. The end timestamp is an epoch-millis bound for consumption, so only zero (unset/absent) or positive values are accepted.","triggerScenarios":"Passing --end-timestamp with a negative number, typically a miscalculated epoch value or a sentinel like -1 used to mean 'disabled'.","commonSituations":"Using -1 as a 'no limit' sentinel (as some tools allow) that this CLI rejects; date math in a script producing a negative epoch; reading a placeholder config value like ${END_TS} that defaults to -1.","solutions":["Omit --end-timestamp entirely when no end bound is wanted instead of passing a negative sentinel","Pass a valid positive epoch-millis value, e.g. $(date +%s000)","Fix the script/config so the default is 0 (unset) rather than -1"],"exampleFix":"// before\nEND_TS=${END_TS:--1}\npulsar-client consume ... --end-timestamp $END_TS\n// after\nif [ -n \"$END_TS\" ] && [ \"$END_TS\" -gt 0 ]; then\n  pulsar-client consume ... --end-timestamp \"$END_TS\"\nelse\n  pulsar-client consume ...\nfi","handlingStrategy":"validation","validationCode":"if [ -n \"$END_TS\" ] && [ \"$END_TS\" -lt 0 ] 2>/dev/null; then\n  echo \"--end-timestamp must be a positive epoch-millis (or omit the flag)\" >&2; exit 2;\nfi","typeGuard":"static boolean isValidEndTimestamp(long ts) { return ts <= 0 || ts > 0; /* 0 means unset; negatives are invalid — use ts >= 0 and omit flag for unset */\nreturn ts >= 0; }","tryCatchPattern":"try {\n    int rc = cmdConsume.run();\n} catch (CommandLine.ParameterException e) {\n    if (e.getMessage().contains(\"end timestamp\")) {\n        System.err.println(\"--end-timestamp must be positive epoch-millis; omit the flag for no bound\");\n        System.exit(2);\n    } else { throw e; }\n}","preventionTips":["Never pass -1 or negative sentinels for timestamps; omit the flag instead","Generate timestamps with $(date +%s000) rather than hand arithmetic","Validate epoch values are > 0 in config generation","Centralize timestamp handling in one wrapper so sentinel behavior is consistent"],"tags":["cli","validation","arguments","timestamp"],"backgroundTag":"invalid-argument-value","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"}