{"record":{"id":"27c2d8a29819c552","repo":"apache/cassandra","slug":"the-length-of-the-provided-dictionary-array-dict","errorCode":null,"errorMessage":"The length of the provided dictionary array (<dict.length>) is not equal to provided length value (<dictLength>).","messagePattern":"The length of the provided dictionary array \\(<dict\\.length>\\) is not equal to provided length value \\(<dictLength>\\)\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/compression/CompressionDictionaryDetailsTabularData.java","lineNumber":314,"sourceCode":"                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 + \").\");\n            if (createdAt == null)\n                throw new IllegalArgumentException(\"The creation date not specified.\");\n\n            int checksumOfDictionaryToImport = CompressionDictionary.calculateChecksum((byte) dictionaryKind.ordinal(), dictId, dict);\n            if (checksumOfDictionaryToImport != dictChecksum)\n            {\n                throw new IllegalArgumentException(format(\"Computed checksum of dictionary to import (%s) is different from checksum specified on input (%s).\",\n                                                          checksumOfDictionaryToImport,\n                                                          dictChecksum));\n            }\n        }\n    }\n}\n","sourceCodeStart":296,"sourceCodeEnd":328,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/compression/CompressionDictionaryDetailsTabularData.java#L296-L328","documentation":"validate() cross-checks that the declared dictLength equals dict.length. A mismatch means the descriptor's metadata disagrees with the actual payload, which would corrupt the import checksum and storage, so it is rejected with both lengths in the message.","triggerScenarios":"Constructing CompressionDictionaryDataObject where dictLength != dict.length — e.g. the length came from stale metadata while the byte array was re-read/truncated, or the caller passed a partial buffer with the original length.","commonSituations":"Truncated dictionary files whose header still declares the original size; off-by-one or unit errors (chars vs bytes) when computing length; mixing descriptors and payloads from different dictionary versions.","solutions":["Pass dict.length as dictLength so both match the actual payload","Re-read the dictionary file completely and regenerate the descriptor from the same buffer","If metadata says otherwise, investigate why the file is truncated or corrupted instead of forcing the length"],"exampleFix":"// before\nnew CompressionDictionaryDataObject(..., dict, headerDeclaredLength, ...);\n// after\nnew CompressionDictionaryDataObject(..., dict, dict.length, ...);","handlingStrategy":"validation","validationCode":"if (obj.dict == null || obj.dictLength != obj.dict.length) throw new IllegalArgumentException(\"dictLength (\" + obj.dictLength + \") must equal dict.length (\" + (obj.dict == null ? -1 : obj.dict.length) + \")\");","typeGuard":"boolean lengthsConsistent(CompressionDictionaryDataObject o) { return o.dict != null && o.dictLength == o.dict.length; }","tryCatchPattern":"try { tabularData.fromDataObject(obj); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"not equal to provided length value\")) { /* rebuild with dictLength = dict.length */ } else throw e; }","preventionTips":["Never pass a separately-sourced length and payload; use dict.length","If length must be carried from metadata, verify it against the buffer before import","Watch for truncated reads that shrink the array but not the declared length"],"tags":["validation","compression-dictionary"],"backgroundTag":"invalid-argument-value","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"}