{"record":{"id":"e906fdfe86ea12fd","repo":"apache/cassandra","slug":"invalid-null-value-for-s","errorCode":null,"errorMessage":"Invalid null value for %s","messagePattern":"Invalid null value for (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/restrictions/SimpleRestriction.java","lineNumber":342,"sourceCode":"    private ByteBuffer bindAndGetSingle(FunctionContext context)\n    {\n        ByteBuffer buffer = values.bindAndGetSingleTermValue(context);\n        validate(buffer);\n        return buffer;\n    }\n\n    private List<List<ByteBuffer>> bindAndGetElements(FunctionContext context)\n    {\n        List<List<ByteBuffer>> elementsList = values.bindAndGetElements(context);\n        validate(elementsList);\n        elementsList.forEach(this::validateElements);\n        return elementsList;\n    }\n\n    private void validate(List<?> list)\n    {\n        if (list == null)\n            throw invalidRequest(\"Invalid null value for %s\", columnsExpression);\n        if (list == Term.UNSET_LIST)\n            throw invalidRequest(\"Invalid unset value for %s\", columnsExpression);\n    }\n\n    private void validate(ByteBuffer buffer)\n    {\n        if (buffer == null)\n            throw invalidRequest(\"Invalid null value for %s\", columnsExpression);\n        if (buffer == ByteBufferUtil.UNSET_BYTE_BUFFER)\n            throw invalidRequest(\"Invalid unset value for %s\", columnsExpression);\n    }\n\n    private void validateElements(List<ByteBuffer> elements)\n    {\n        validate(elements);\n\n        List<ColumnMetadata> columns = columns();\n        for (int i = 0, m = columns.size(); i < m; i++)","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/restrictions/SimpleRestriction.java#L324-L360","documentation":"A restriction term bound to null is rejected: SimpleRestriction.validate(List) throws when the bound list value for the restricted columns expression is null. Cassandra requires concrete bound values for restriction terms; null cannot be used as a comparison operand.","triggerScenarios":"Executing a prepared statement without setting a bound value for the restriction column (bound term resolves to null).","commonSituations":"Forgetting to bind a variable before executing a prepared statement; driver defaults unset positional parameters to null in a List-typed restriction.","solutions":["Set the bound variable with the driver (e.g. boundStatement.setString(i, value)) before executing","Validate all bound parameters are non-null client-side before execute","Remove the restriction clause instead of passing null when filtering is not intended"],"exampleFix":"// before\nPreparedStatement ps = session.prepare(\"SELECT * FROM t WHERE k IN ?\");\nsession.execute(ps.bind());\n// after\nPreparedStatement ps = session.prepare(\"SELECT * FROM t WHERE k IN ?\");\nsession.execute(ps.bind(Arrays.asList(1, 2)));","handlingStrategy":"validation","validationCode":"// before executing a bound statement\nfor (int i = 0; i < values.length; i++) if (values[i] == null) throw new IllegalArgumentException(\"bind value \" + i + \" is null\");","typeGuard":"boolean isBound(Object v) { return v != null; }","tryCatchPattern":"catch (InvalidRequestException e) { if (e.getMessage().startsWith(\"Invalid null value\")) logMissingBindings(); }","preventionTips":["Always bind all placeholder parameters before execute","Use driver-side statements that fail fast on missing bindings","Track required parameters in a query-builder abstraction"],"tags":["cql","prepared-statement","null-value","query-validation"],"backgroundTag":"null-argument","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"}