{"record":{"id":"5d892a8d7d1af2d0","repo":"apache/cassandra","slug":"the-negation-of-increment-overflows-suppor","errorCode":null,"errorMessage":"The negation of \" + increment + \" overflows supported counter precision (signed 8 bytes integer)","messagePattern":"The negation of \" \\+ increment \\+ \" overflows supported counter precision \\(signed 8 bytes integer\\)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/terms/Constants.java","lineNumber":580,"sourceCode":"        @Override\n        public boolean requiresRead()\n        {\n            return !column.type.isCounter();\n        }\n\n        public void execute(DecoratedKey partitionKey, RowUpdateBuilder builder) throws InvalidRequestException\n        {\n            if (column.type instanceof CounterColumnType)\n            {\n                ByteBuffer bytes = t.bindAndGet(builder);\n                if (bytes == null)\n                    throw new InvalidRequestException(\"Invalid null value for counter increment\");\n                if (bytes == ByteBufferUtil.UNSET_BYTE_BUFFER)\n                    return;\n\n                long increment = ByteBufferUtil.toLong(bytes);\n                if (increment == Long.MIN_VALUE)\n                    throw new InvalidRequestException(\"The negation of \" + increment + \" overflows supported counter precision (signed 8 bytes integer)\");\n\n                builder.addCounter(column, -increment);\n            }\n            else if (column.type instanceof NumberType<?>)\n            {\n                @SuppressWarnings(\"unchecked\") NumberType<Number> type = (NumberType<Number>) column.type;\n                ByteBuffer increment = type.sanitize(t.bindAndGet(builder));\n                if (increment == null)\n                    return;\n                ByteBuffer current = type.sanitize(getCurrentCellBuffer(column, partitionKey, builder));\n                if (current == null)\n                    return;\n                ByteBuffer newValue = type.substract(type.compose(current), type.compose(increment));\n                builder.addCell(column, newValue);\n            }\n        }\n    }\n","sourceCodeStart":562,"sourceCodeEnd":598,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/terms/Constants.java#L562-L598","documentation":"Thrown when negating a counter delta equal to Long.MIN_VALUE (-9223372036854775808). Because -Long.MIN_VALUE overflows in signed 64-bit arithmetic, Cassandra rejects it explicitly instead of silently wrapping the counter.","triggerScenarios":"`UPDATE t SET c = -?` where the bound value is exactly Long.MIN_VALUE; literal `SET c = c - (-9223372036854775808)` style extreme deltas.","commonSituations":"Stress tests or data corruption scenarios using extreme long values; unvalidated user-supplied deltas reaching the extreme negative bound.","solutions":["Clamp or validate the delta so it is strictly greater than Long.MIN_VALUE before binding","Split the operation into two smaller counter updates if an equivalent huge decrement is truly needed","Log/reject at the application layer when delta == Long.MIN_VALUE"],"exampleFix":"// before\nlong delta = Long.MIN_VALUE;\nsession.execute(\"UPDATE t SET c = c - ?\", delta);\n// after\nif (delta == Long.MIN_VALUE) throw new IllegalArgumentException(\"delta too small\");\nsession.execute(\"UPDATE t SET c = c - ?\", delta);","handlingStrategy":"validation","validationCode":"if (delta == Long.MIN_VALUE) throw new IllegalArgumentException(\"delta cannot be negated\");","typeGuard":null,"tryCatchPattern":"try { session.execute(stmt); } catch (InvalidQueryException e) { if (e.getMessage().contains(\"overflows supported counter precision\")) { /* clamp or split the delta */ } else throw e; }","preventionTips":["Clamp counter deltas away from Long.MIN_VALUE","Validate user-supplied deltas against a sane range","Avoid extreme sentinel long values as deltas"],"tags":["cql","counter","overflow","arithmetic"],"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"}