{"record":{"id":"440ac994b31c98ff","repo":"apache/cassandra","slug":"null-is-not-supported-inside-vectors","errorCode":null,"errorMessage":"null is not supported inside vectors","messagePattern":"null is not supported inside vectors","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/VectorType.java","lineNumber":213,"sourceCode":"        return filterSortAndValidateElements(buffers, ByteBufferUtil.UNSET_BYTE_BUFFER, ByteBufferAccessor.instance);\n    }\n\n    @Override\n    public List<byte[]> filterSortAndValidateElementsFromArrays(List<byte[]> buffers)\n    {\n        return filterSortAndValidateElements(buffers, ByteArrayUtil.UNSET_BYTE_ARRAY, ByteArrayAccessor.instance);\n    }\n\n    public <V> List<V> filterSortAndValidateElements(List<V> buffers, V unsetValue, ValueAccessor<V> valueAccessor)\n    {\n        // We only filter and validate for this type.\n        if (buffers == null)\n            return null;\n\n        for (V buffer : buffers)\n        {\n            if (buffer == null || elementType.isNull(buffer, valueAccessor))\n                throw new MarshalException(\"null is not supported inside vectors\");\n\n            if (buffer == unsetValue)\n                throw new InvalidRequestException(\"unset is not supported inside vectors\");\n\n            elementType.validate(buffer, valueAccessor);\n        }\n        return buffers;\n    }\n\n    @Override\n    public <V> ByteSource asComparableBytes(ValueAccessor<V> accessor, V value, ByteComparable.Version version)\n    {\n        if (isNull(value, accessor))\n            return null;\n        ByteSource[] srcs = new ByteSource[dimension];\n        List<V> split = unpack(value, accessor);\n        for (int i = 0; i < dimension; i++)\n            srcs[i] = elementType.asComparableBytes(accessor, split.get(i), version);","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/VectorType.java#L195-L231","documentation":"When marshalling/validating a vector value, Cassandra checks each element buffer and rejects any null (or element buffer whose element type reports isNull). Vectors are fixed-size collections and null elements are not representable, so MarshalException is thrown.","triggerScenarios":"Binding a Java List/array containing null elements for a vector column (e.g. List<ByteBuffer> with a null entry, or Integer[] with nulls for vector<int>), then inserting or validating via filterSortAndValidateElements.","commonSituations":"Application code building vector values from data that may contain nulls (missing embeddings, optional fields); deserialization paths feeding null entries into vector composition.","solutions":["Replace null elements with type-appropriate defaults before binding","Filter out or reject rows with null elements before constructing the vector","Store a sentinel value (e.g. 0.0f for float vectors) instead of null","Use try-catch around marshal if nulls are possible and handle gracefully"],"exampleFix":"// before\nList<Integer> values = Arrays.asList(1, null, 3);\nByteBuffer buf = vectorType.decompose(values);\n// after\nList<Integer> values = Arrays.asList(1, 0, 3); // no nulls\nByteBuffer buf = vectorType.decompose(values);","handlingStrategy":"validation","validationCode":"boolean hasNull = values == null || values.stream().anyMatch(Objects::isNull);\nif (hasNull) throw new IllegalArgumentException(\"null elements not allowed in vector\");","typeGuard":"boolean hasNoNulls = values != null && values.stream().noneMatch(Objects::isNull);","tryCatchPattern":"try { buf = vt.decompose(values); } catch (MarshalException e) { /* handle null elements */ }","preventionTips":["Sanitize nullable fields before building vectors","Use sentinel values for missing elements"],"tags":["cassandra","vector-type","null","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-14T16:17:12.679Z"}