{"record":{"id":"544383773e383fb9","repo":"apache/cassandra","slug":"column-value-does-not-satisfy-value-constraint-for-544383","errorCode":null,"errorMessage":"Column value does not satisfy value constraint for column '<columnName>'. It has a length of <valueLength> and it should be <relationType> <term>","messagePattern":"Column value does not satisfy value constraint for column '<columnName>'\\. It has a length of <valueLength> and it should be <relationType> <term>","errorType":"validation","errorClass":"ConstraintViolationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/constraints/LengthConstraint.java","lineNumber":57,"sourceCode":"        super(name, args);\n    }\n\n    public LengthConstraint(List<String> args)\n    {\n        this(NAME, args);\n    }\n\n    @Override\n    public void internalEvaluate(AbstractType<?> valueType, Operator relationType, String term, ByteBuffer columnValue)\n    {\n        int valueLength = getValueLength(columnValue, valueType);\n        int sizeConstraint = Integer.parseInt(term);\n\n        ByteBuffer leftOperand = ByteBufferUtil.bytes(valueLength);\n        ByteBuffer rightOperand = ByteBufferUtil.bytes(sizeConstraint);\n\n        if (!relationType.isSatisfiedBy(Int32Type.instance, leftOperand, rightOperand))\n            throw new ConstraintViolationException(\"Column value does not satisfy value constraint for column '\" + columnName + \"'. \"\n                                                   + \"It has a length of \" + valueLength + \" and it should be \"\n                                                   + relationType + ' ' + term);\n    }\n\n    @Override\n    public List<Operator> getSupportedOperators()\n    {\n        return DEFAULT_FUNCTION_OPERATORS;\n    }\n\n    @Override\n    public List<AbstractType<?>> getSupportedTypes()\n    {\n        return SUPPORTED_TYPES;\n    }\n\n    private int getValueLength(ByteBuffer value, AbstractType<?> valueType)\n    {","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/constraints/LengthConstraint.java#L39-L75","documentation":"LengthConstraint.internalEvaluate compares the actual byte length of the written value against the constraint's numeric term using the given operator (e.g. >=, <=) and throws ConstraintViolationException when the relation is not satisfied. The message reports the value's length, the required operator, and the required bound.","triggerScenarios":"INSERT/UPDATE where the value length (in bytes) fails the declared length relation, e.g. a column constrained to `LENGTH() >= 5` receiving a 3-byte string, or `LENGTH() <= 10` receiving a 20-character string. The term must parse as an int.","commonSituations":"Users assuming LENGTH counts characters for multi-byte UTF-8 text (it counts bytes); password/username policies not enforced client-side; ALTERing constraints after data of other sizes exists (new writes then fail).","solutions":["Shorten or lengthen the written value so its byte length satisfies the constraint.","Relax the constraint bounds in the schema (ALTER TABLE) to accommodate real data sizes.","Count bytes (not chars) in client-side validation to mirror the constraint.","Verify the term in the constraint is the intended integer bound."],"exampleFix":"// before (constraint LENGTH() >= 8)\nstmt.bindString(\"password\", \"abc\");\n// after\nString pw = \"abc\";\nif (pw.getBytes(StandardCharsets.UTF_8).length < 8) pw = padOrReject(pw);\nstmt.bindString(\"password\", pw);","handlingStrategy":"validation","validationCode":"int len = value.getBytes(StandardCharsets.UTF_8).length;\nif (!relationSatisfied(len, minOrMax))\n    throw new IllegalArgumentException(\"length \" + len + \" violates constraint \" + relationType + \" \" + term);","typeGuard":null,"tryCatchPattern":"try {\n    session.execute(write);\n} catch (ConstraintViolationException e) {\n    if (e.getMessage().contains(\"It has a length of\")) {\n        // truncate/extend value or relax the constraint\n    } else throw e;\n}","preventionTips":["Compute lengths in bytes (UTF-8), matching the server's semantics","Mirror constraint bounds in client-side validation (bean validation)","Re-check constraints after ALTERing column sizes or constraint terms"],"tags":["cql","write-path","constraints","length","validation"],"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-14T16:17:12.679Z"}