{"record":{"id":"61b811fc8cee8215","repo":"apache/cassandra","slug":"invalid-ttl-value-tval","errorCode":null,"errorMessage":"Invalid TTL value: <tval>","messagePattern":"Invalid TTL value: <tval>","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/Attributes.java","lineNumber":135,"sourceCode":"        ByteBuffer tval = timeToLive.bindAndGet(context);\n        if (tval == null)\n            return 0;\n\n        if (tval == ByteBufferUtil.UNSET_BYTE_BUFFER)\n            return metadata.params.defaultTimeToLive;\n\n        // byte[0] and null are the same for Int32Type.  UNSET_BYTE_BUFFER is also byte[0] but we rely on pointer\n        // identity, so need to check this after checking that\n        if (ByteBufferUtil.EMPTY_BYTE_BUFFER.equals(tval))\n            return 0;\n\n        try\n        {\n            Int32Type.instance.validate(tval);\n        }\n        catch (MarshalException e)\n        {\n            throw new InvalidRequestException(\"Invalid TTL value: \" + tval);\n        }\n\n        int ttl = Int32Type.instance.compose(tval);\n        if (ttl < 0)\n            throw new InvalidRequestException(\"A TTL must be greater or equal to 0, but was \" + ttl);\n\n        if (ttl > MAX_TTL)\n            throw new InvalidRequestException(String.format(\"ttl is too large. requested (%d) maximum (%d)\", ttl, MAX_TTL));\n\n        if (metadata.params.defaultTimeToLive != LivenessInfo.NO_TTL && ttl == LivenessInfo.NO_TTL)\n            return LivenessInfo.NO_TTL;\n\n        ExpirationDateOverflowHandling.maybeApplyExpirationDateOverflowPolicy(metadata, ttl, false);\n\n        return ttl;\n    }\n\n    public void collectMarkerSpecification(VariableSpecifications boundNames)","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/Attributes.java#L117-L153","documentation":"Attributes.getTimeToLive resolves the USING TTL term; the bound value must be a valid Int32Type-encoded 4-byte int. If Int32Type.instance.validate throws MarshalException, the method throws InvalidRequestException 'Invalid TTL value: <bytes>'. This is a format validation of the bound TTL bytes, separate from range checks.","triggerScenarios":"'USING TTL ?' bound with byte values that are not a valid int32 serialization (wrong length, string bytes, oversized long) through raw term binding paths.","commonSituations":"Custom query handlers or thrift-era code assembling bound values manually; binding a long TTL into an int slot with a full 8-byte buffer; drivers sending text-encoded numbers.","solutions":["Bind the TTL as a Java int through the driver instead of raw buffers","Encode with Int32Type.instance.decompose(ttl) in custom code","Ensure the value fits in 32-bit signed int and is 4 bytes big-endian","Re-check the driver/API used to bind USING TTL values"],"exampleFix":"// before\nByteBuffer ttlBytes = ByteBuffer.allocate(8).putLong(3600L); // 8 bytes\n// after\nByteBuffer ttlBytes = Int32Type.instance.decompose(3600); // valid int32","handlingStrategy":"validation","validationCode":"void validateTtlBytes(ByteBuffer tval) {\n    try { org.apache.cassandra.db.marshal.Int32Type.instance.validate(tval); }\n    catch (org.apache.cassandra.serializers.MarshalException e) {\n        throw new IllegalArgumentException(\"ttl must be an int32-encoded buffer\", e);\n    }\n}","typeGuard":"boolean isIntEncoded(ByteBuffer b) { return b != null && b.remaining() == 4; }","tryCatchPattern":"try {\n    session.execute(bs);\n} catch (InvalidQueryException e) {\n    if (e.getMessage().startsWith(\"Invalid TTL value\"))\n        log.error(\"Bind USING TTL as int via driver typed setters\");\n    throw e;\n}","preventionTips":["Bind TTL as Java int, never long/string buffers","Use Int32Type.instance.decompose() for raw encoding","Keep TTL values within int range before binding","Test custom bind paths that populate USING TTL terms"],"tags":["cql","ttl","type-mismatch"],"backgroundTag":"invalid-argument-format","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}