{"record":{"id":"c75cae2e90b50d04","repo":"apache/cassandra","slug":"receiving-type-receivetype-does-not-match-type","errorCode":null,"errorMessage":"Receiving type {receiveType} does not match {type}","messagePattern":"Receiving type (.+?) does not match (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/accord/txn/TxnReference.java","lineNumber":442,"sourceCode":"            // TODO: confirm all references can be satisfied as part of the txn condition\n            AbstractType<?> type = column().type;\n\n            // Modify the type we'll check if the reference is to a collection element.\n            if (selectsPath())\n            {\n                if (type.isCollection())\n                {\n                    CollectionType<?> collectionType = (CollectionType<?>) type;\n                    type = collectionType.kind == SET ? collectionType.nameComparator() : collectionType.valueComparator();\n                }\n                else if (type.isUDT())\n                    type = getFieldSelectionType();\n            }\n\n            // Account for frozen collection and reversed clustering key references:\n            AbstractType<?> receiveType = type.isFrozenCollection() ? receiver.freeze().unwrap() : receiver.unwrap();\n            if (!(receiveType == type.unwrap()))\n                throw new IllegalArgumentException(\"Receiving type \" + receiveType + \" does not match \" + type.unwrap());\n\n            if (column().isPartitionKey())\n                return getPartitionKey(data);\n            else if (column().isClusteringColumn())\n                return getClusteringKey(data);\n\n            ColumnData columnData = getColumnData(data);\n\n            if (columnData == null)\n                return null;\n\n            if (selectsComplex())\n            {\n                ComplexColumnData complex = (ComplexColumnData) columnData;\n\n                if (type instanceof CollectionType)\n                {\n                    CollectionType<?> col = (CollectionType<?>) type;","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/accord/txn/TxnReference.java#L424-L460","documentation":"TxnReference.toByteBuffer() validates that the receiver's type matches the referenced field's type (accounting for frozen collections and reversed clustering keys) before extracting raw bytes. If the receiving type differs from the reference's type, the reference cannot be safely applied, and an IllegalArgumentException is thrown.","triggerScenarios":"Constructing a transaction reference (TxnReference) whose receiver column type differs from the referenced value's type — e.g. applying a write computed against one column type into a receiver column of a different (unwrapped) type, or referencing a key/clustering value with the wrong type after schema changes.","commonSituations":"Schema migrations that changed a column's type while transactions referencing the old type are in flight; bugs in transaction-building code that mismatch receiver and reference types; frozen collection handling errors.","solutions":["Fix transaction construction so the receiver's unwrapped type equals the reference's unwrapped type","If a schema change altered the column type, rebuild/retry the affected transactions against the new schema","Check frozen-collection handling: ensure freeze()/unwrap() is applied symmetrically on both sides","Verify the field selection type (getFieldSelectionType) matches the actual column type"],"exampleFix":"// before\nTxnReference ref = new TxnReference(tableId, receiverColumn, referenceColumn /* type mismatch after ALTER */);\n// after\nAbstractType<?> expected = receiverColumn.isFrozenCollection() ? receiverColumn.freeze().unwrap() : receiverColumn.unwrap();\nInvariants.requireArgument(expected.equals(referenceColumn.unwrap()), \"Receiver type %s must match reference type %s\", expected, referenceColumn.unwrap());","handlingStrategy":"validation","validationCode":"AbstractType<?> recv = receiver.isFrozenCollection() ? receiver.freeze().unwrap() : receiver.unwrap();\nAbstractType<?> ref  = referenceType.isFrozenCollection() ? referenceType.freeze().unwrap() : referenceType.unwrap();\nif (!recv.equals(ref)) throw new IllegalArgumentException(\"Receiver type \" + recv + \" != reference type \" + ref);","typeGuard":"static boolean typesMatch(AbstractType<?> receiver, AbstractType<?> reference) {\n    return unwrapCompatible(receiver).equals(unwrapCompatible(reference));\n}","tryCatchPattern":"try { ByteBuffer buf = ref.toByteBuffer(); }\ncatch (IllegalArgumentException e) { /* type mismatch — rebind the txn against current schema */ }","preventionTips":["Rebuild in-flight transactions after ALTER TABLE type changes","Compare unwrapped types (not raw AbstractType references) when validating","Add asserts at transaction-build time so mismatches fail before commit time"],"tags":["accord","type-mismatch","transaction-references"],"backgroundTag":"type-mismatch","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"}