{"record":{"id":"ce2b44ea8a6bed8b","repo":"apache/cassandra","slug":"provided-dictionary-byte-array-is-null-or-empty","errorCode":null,"errorMessage":"Provided dictionary byte array is null or empty.","messagePattern":"Provided dictionary byte array is null or empty\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/compression/CompressionDictionaryDetailsTabularData.java","lineNumber":296,"sourceCode":"         *     <li>kind is not null and there is such {@link org.apache.cassandra.db.compression.CompressionDictionary.Kind}</li>\n         *     <li>dictLength is bigger than 0</li>\n         *     <li>dictLength has to be equal to dict's length</li>\n         *     <li>dictChecksum has to be equal to checksum computed as part of this method</li>\n         *     <li>creation date is not null</li>\n         * </ul>\n         */\n        private void validate()\n        {\n            if (keyspace == null)\n                throw new IllegalArgumentException(\"Keyspace not specified.\");\n            if (table == null)\n                throw new IllegalArgumentException(\"Table not specified.\");\n            if (tableId == null)\n                throw new IllegalArgumentException(\"Table id not specified.\");\n            if (dictId <= 0)\n                throw new IllegalArgumentException(\"Provided dictionary id must be positive but it is '\" + dictId + \"'.\");\n            if (dict == null || dict.length == 0)\n                throw new IllegalArgumentException(\"Provided dictionary byte array is null or empty.\");\n            if (kind == null)\n                throw new IllegalArgumentException(\"Provided kind is null.\");\n\n            CompressionDictionary.Kind dictionaryKind;\n\n            try\n            {\n                dictionaryKind = CompressionDictionary.Kind.valueOf(kind);\n            }\n            catch (IllegalArgumentException ex)\n            {\n                throw new IllegalArgumentException(\"There is no such dictionary kind like '\" + kind + \"'. Available kinds: \" + Arrays.asList(CompressionDictionary.Kind.values()));\n            }\n\n            if (dictLength <= 0)\n                throw new IllegalArgumentException(\"Size has to be strictly positive number, it is '\" + dictLength + \"'.\");\n            if (dict.length != dictLength)\n                throw new IllegalArgumentException(\"The length of the provided dictionary array (\" + dict.length + \") is not equal to provided length value (\" + dictLength + \").\");","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/compression/CompressionDictionaryDetailsTabularData.java#L278-L314","documentation":"validate() requires the dictionary payload byte array to be non-null and non-empty. An imported dictionary with no bytes cannot be trained-used for compression and would be useless, so it is rejected early.","triggerScenarios":"Passing dict == null or a zero-length byte[] into CompressionDictionaryDataObject — e.g. the dictionary file failed to be read, or the caller built the descriptor without loading the dictionary contents.","commonSituations":"Import tooling that read an empty/missing dictionary file; I/O errors swallowed upstream so the byte array stayed null; truncation that produced an empty buffer.","solutions":["Load the actual dictionary bytes from the file/storage before constructing the data object","Check the dictionary file exists and is non-empty prior to import","Ensure the read code's error paths do not silently produce null/empty arrays"],"exampleFix":"// before\nbyte[] dict = new byte[0]; // never loaded\n// after\nbyte[] dict = Files.readAllBytes(Paths.get(dictionaryFile));\nif (dict.length == 0) throw new IOException(\"Dictionary file is empty: \" + dictionaryFile);","handlingStrategy":"validation","validationCode":"if (obj.dict == null || obj.dict.length == 0) throw new IllegalArgumentException(\"dictionary payload must be non-null and non-empty\");","typeGuard":"boolean hasPayload(CompressionDictionaryDataObject o) { return o.dict != null && o.dict.length > 0; }","tryCatchPattern":"try { tabularData.fromDataObject(obj); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"dictionary byte array is null or empty\")) { /* reload the dictionary bytes from disk */ } else throw e; }","preventionTips":["Load dictionary bytes with a failing read (Files.readAllBytes) instead of nullable I/O paths","Check the dictionary file size > 0 before import","Do not swallow I/O exceptions when reading the dictionary"],"tags":["validation","compression-dictionary"],"backgroundTag":"empty-required-field","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"}