{"record":{"id":"f0aece1a58a25df6","repo":"NationalSecurityAgency/ghidra","slug":"cannot-advance-a-negative-number","errorCode":null,"errorMessage":"Cannot advance a negative number","messagePattern":"Cannot advance a negative number","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/time/schedule/AbstractStep.java","lineNumber":86,"sourceCode":"\t\treturn tickCount;\n\t}\n\n\t@Override\n\tpublic long getPatchCount() {\n\t\treturn 0;\n\t}\n\n\t@Override\n\tpublic abstract AbstractStep clone();\n\n\t/**\n\t * Add to the count of this step\n\t * \n\t * @param steps the count to add\n\t */\n\tpublic void advance(long steps) {\n\t\tif (steps < 0) {\n\t\t\tthrow new IllegalArgumentException(\"Cannot advance a negative number\");\n\t\t}\n\t\tlong newCount = tickCount + steps;\n\t\tif (newCount < 0) {\n\t\t\tthrow new IllegalArgumentException(\"Total step count exceeds LONG_MAX\");\n\t\t}\n\t\tthis.tickCount = newCount;\n\t}\n\n\t@Override\n\tpublic long rewind(long steps) {\n\t\tif (steps < 0) {\n\t\t\tthrow new IllegalArgumentException(\"Cannot rewind a negative number\");\n\t\t}\n\t\tlong diff = this.tickCount - steps;\n\t\tthis.tickCount = Long.max(0, diff);\n\t\treturn -diff;\n\t}\n","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/time/schedule/AbstractStep.java#L68-L104","documentation":"Thrown by AbstractStep.advance(long steps) when steps < 0. advance() only grows a step's tick count, so a negative argument (a request to shrink via advance) is rejected; use rewind() to reduce the count.","triggerScenarios":"Calling step.advance(n) with a negative n, often because a computed delta was negative.","commonSituations":"Reusing the same delta for both forward and backward movement; off-by-one in schedule arithmetic producing a negative increment.","solutions":["Route reductions through rewind(): if (steps >= 0) advance(steps); else rewind(-steps).","Ensure the delta passed to advance is non-negative at the call site.","Prefer TraceSchedule-level APIs that handle direction."],"exampleFix":"// before\nstep.advance(delta); // delta < 0 -> exception\n\n// after\nif (delta >= 0) step.advance(delta);\nelse step.rewind(-delta);","handlingStrategy":"validation","validationCode":"if (delta >= 0) step.advance(delta);\nelse step.rewind(-delta);","typeGuard":"static boolean validAdvance(long steps) { return steps >= 0; }","tryCatchPattern":null,"preventionTips":["Pick advance vs rewind from the sign of the delta rather than always calling advance.","Keep a single source of truth for schedule deltas."],"tags":["ghidra","trace-modeling","schedule","step","illegal-argument"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}