{"record":{"id":"72b5173646f04122","repo":"apache/cassandra","slug":"column-value-does-not-satisfy-value-constraint-for-72b517","errorCode":null,"errorMessage":"Column value does not satisfy value constraint for column '<columnName>' as it is null.","messagePattern":"Column value does not satisfy value constraint for column '<columnName>' as it is null\\.","errorType":"validation","errorClass":"ConstraintViolationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/constraints/ConstraintFunction.java","lineNumber":72,"sourceCode":"    {\n        this.name = name;\n        this.rawArgs = args;\n        this.args = unquote(args);\n    }\n\n    public List<String> arguments()\n    {\n        return args;\n    }\n\n    /**\n     * Method that performs the actual condition test, executed during the write path.\n     * It the test is not successful, it throws a {@link ConstraintViolationException}.\n     */\n    public void evaluate(AbstractType<?> valueType, Operator relationType, String term, ByteBuffer columnValue) throws ConstraintViolationException\n    {\n        if (columnValue == ByteBufferUtil.EMPTY_BYTE_BUFFER)\n            throw new ConstraintViolationException(\"Column value does not satisfy value constraint for column '\" + columnName + \"' as it is null.\");\n        else if (valueType.isEmptyValueMeaningless() && columnValue.capacity() == 0)\n            throw new ConstraintViolationException(\"Column value does not satisfy value constraint for column '\" + columnName + \"' as it is empty.\");\n\n        internalEvaluate(valueType, relationType, term, columnValue);\n    }\n\n    /**\n     * Internal evaluation method, by default called from {@link ConstraintFunction#evaluate(AbstractType, Operator, String, ByteBuffer)}.\n     * {@code columnValue} is by default guaranteed to not represent CQL value of 'null'.\n     */\n    protected abstract void internalEvaluate(AbstractType<?> valueType, Operator relationType, String term, ByteBuffer columnValue);\n\n    /**\n     * Used mostly for unary functions which do not expect any relation type nor term.\n     */\n    public void evaluate(AbstractType<?> valueType, ByteBuffer columnValue) throws ConstraintViolationException\n    {\n        evaluate(valueType, null, null, columnValue);","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/constraints/ConstraintFunction.java#L54-L90","documentation":"ConstraintFunction.evaluate runs user constraints on the write path and rejects a null column value before internal evaluation. Technically it triggers when columnValue equals ByteBufferUtil.EMPTY_BYTE_BUFFER, which the code treats as null, throwing ConstraintViolationException because the value cannot satisfy the constraint. This prevents constraints from silently passing on absent data.","triggerScenarios":"INSERT/UPDATE writing a null (or the empty ByteBuffer sentinel) to a column that carries a ConstraintFunction-based constraint; e.g. `INSERT INTO ks.t (id, name) VALUES (uuid(), null)` where name has a LENGTH/JSON/NOT-NULL-style constraint evaluated via evaluate().","commonSituations":"Application code that binds null for missing fields; partial updates that null out a constrained column; ORMs that serialize missing properties as nulls.","solutions":["Provide a non-null value for the constrained column in the write.","Remove the constraint from the column if nulls must be allowed.","Use an IF NOT EXISTS / application-side check to skip writing when the value would be null."],"exampleFix":"// before\nstmt.bind(id, null);\n// after\nstmt.bind(id, name == null ? \"default\" : name);","handlingStrategy":"try-catch","validationCode":"if (value == null) throw new IllegalArgumentException(\"Column \" + columnName + \" requires a non-null value due to a constraint\");","typeGuard":null,"tryCatchPattern":"try {\n    session.execute(write);\n} catch (ConstraintViolationException e) {\n    if (e.getMessage().contains(\"as it is null\")) {\n        // supply default or skip write\n    } else throw e;\n}","preventionTips":["Bind null as null via driver defaults, never empty buffers","Coalesce nulls to defaults in application code before writes","Avoid updating constrained columns to null; use tombstone-aware logic"],"tags":["cql","write-path","constraints","null-value"],"backgroundTag":"null-argument","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"}