{"record":{"id":"ddab4d0ae4fd6626","repo":"apache/cassandra","slug":"number-of-commands-to-display-has-to-be-at-least-1","errorCode":null,"errorMessage":"Number of commands to display has to be at least 1.","messagePattern":"Number of commands to display has to be at least 1\\.","errorType":"console","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/tools/nodetool/History.java","lineNumber":44,"sourceCode":"import org.apache.cassandra.tools.NodeTool;\n\nimport picocli.CommandLine;\nimport picocli.CommandLine.Command;\nimport picocli.CommandLine.Option;\n\n@Command(name = \"history\", description = \"Print previously executed nodetool commands\")\npublic class History extends AbstractCommand implements LocalCommand\n{\n    @Option(paramLabel = \"commands\",\n    names = { \"-n\", \"--num\", \"--number-of-commands\" },\n    description = \"Number of commands to print, defaults to 1000.\")\n    public int commands = 1000;\n\n    @Override\n    protected void execute(NodeProbe probe)\n    {\n        if (commands < 1)\n            throw new IllegalArgumentException(\"Number of commands to display has to be at least 1.\");\n\n        File historyFile = getHistoryFile();\n        validateHistoryFile(historyFile);\n\n        for (String line : commandsToPrint(historyFile))\n            output.out.println(line);\n    }\n\n    @Override\n    protected boolean shouldConnect() throws CommandLine.ExecutionException\n    {\n        return false;\n    }\n\n    File getHistoryFile()\n    {\n        return NodeTool.getHistoryFile();\n    }","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/tools/nodetool/History.java#L26-L62","documentation":"The History nodetool command has a `-n/--commands` option (default 1000) controlling how many recent nodetool commands to print. execute() validates it and throws IllegalArgumentException if the value is less than 1, since printing 'zero or negative' commands is meaningless.","triggerScenarios":"Running `nodetool history -n 0` or `nodetool history -n -5`, or passing an empty/0 value via a script variable.","commonSituations":"Scripts computing a limit that evaluates to 0 (e.g. subtracting counts); users trying to 'disable' history printing by passing 0; off-by-one when trimming output.","solutions":["Pass a positive integer, e.g. `nodetool history -n 50`","Fix the script that computes the count so it clamps to at least 1","Omit -n entirely to use the default of 1000"],"exampleFix":"// before\nnodetool history -n 0\n// after\nnodetool history -n 1   # or omit -n for default 1000","handlingStrategy":"validation","validationCode":"# clamp the command count before invoking\nif [ \"$N\" -lt 1 ]; then echo \"-n must be >= 1\"; exit 1; fi","typeGuard":null,"tryCatchPattern":"try { runNodetool(\"history\",\"-n\",String.valueOf(n)); } catch (IllegalArgumentException e) { log(\"invalid -n: \" + n, e); }","preventionTips":["Ensure script-computed counts are clamped to >= 1","Use Math.max(1, n) when computing the limit in code","Omit -n to accept the default of 1000"],"tags":["nodetool","cli","validation","argument"],"backgroundTag":"value-out-of-range","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}