{"record":{"id":"177ea03a2a921eef","repo":"apache/cassandra","slug":"value-of-type","errorCode":null,"errorMessage":"Value of type ","messagePattern":"Value of type ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/tcm/ClusterMetadata.java","lineNumber":940,"sourceCode":"                consensusMigrationState = new ConsensusMigrationState(Epoch.EMPTY, newTableMigrationStates);\n            }\n            return this;\n        }\n\n        public Transformer with(ConsensusMigrationState consensusMigrationState)\n        {\n            this.consensusMigrationState = consensusMigrationState;\n            return this;\n        }\n\n        public Transformer with(ExtensionKey<?, ?> key, ExtensionValue<?> obj)\n        {\n            if (MetadataKeys.CORE_METADATA.containsKey(key))\n                throw new IllegalArgumentException(\"Core cluster metadata objects should be addressed directly, \" +\n                                                   \"not using the associated MetadataKey\");\n\n            if (!key.valueType.isInstance(obj))\n                throw new IllegalArgumentException(\"Value of type \" + obj.getClass() +\n                                                   \" is incompatible with type for key \" + key +\n                                                   \" (\" + key.valueType + \")\");\n\n            extensions.put(key, obj);\n            modifiedKeys.add(key);\n            return this;\n        }\n\n        public Transformer withIfAbsent(ExtensionKey<?, ?> key, ExtensionValue<?> obj)\n        {\n            if (extensions.containsKey(key))\n                return this;\n            return with(key, obj);\n        }\n\n        public Transformer without(ExtensionKey<?, ?> key)\n        {\n            if (MetadataKeys.CORE_METADATA.containsKey(key))","sourceCodeStart":922,"sourceCodeEnd":958,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/tcm/ClusterMetadata.java#L922-L958","documentation":"ClusterMetadataTransformer.with(key, value) type-checks the value against the ExtensionKey's declared valueType. If obj is not an instance of key.valueType, an IllegalArgumentException naming the actual and expected types is thrown.","triggerScenarios":"Calling with(ExtensionKey, ExtensionValue) where !key.valueType.isInstance(obj) — e.g. putting an object of the wrong class under an extension key, or mixing up keys between two extension types.","commonSituations":"Generic code passing Object/erased values, two extension keys with similar names swapped, or a value class changed without updating the ExtensionKey's valueType after a version upgrade.","solutions":["Pass a value whose runtime class matches (is an instance of) key.valueType.","Use the correct ExtensionKey for the value type being stored.","Add a local assert/instanceof check before calling with()."],"exampleFix":"// before\ntransformer.with(MY_KEY, stringValue); // MY_KEY.valueType is Integer\n// after\ntransformer.with(MY_KEY, 42); // or use the key matching stringValue's type","handlingStrategy":"type-guard","validationCode":"if (!key.valueType.isInstance(value))\n    throw new IllegalArgumentException(\"Value \" + value + \" does not match key type \" + key.valueType);","typeGuard":"static <T> boolean matchesKeyType(ExtensionKey<T,?> key, Object value) {\n    return key.valueType.isInstance(value);\n}","tryCatchPattern":"try {\n    transformer.with(key, obj);\n} catch (IllegalArgumentException e) {\n    logger.error(\"Extension value type mismatch: {}\", e.getMessage());\n}","preventionTips":["Keep ExtensionKey declarations and value classes together and versioned","Prefer generics that tie the key to its value type at compile time","Assert instanceof before calling with() in generic code paths"],"tags":["cassandra","tcm","transformer","type-safety"],"backgroundTag":"type-mismatch","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"}