{"record":{"id":"7ce390d3f5d23833","repo":"apache/cassandra","slug":"codec-not-found-for-requested-operation-s","errorCode":null,"errorMessage":"Codec not found for requested operation: [%s <-> %s]","messagePattern":"Codec not found for requested operation: \\[(.+?) <-> (.+?)\\]","errorType":"exception","errorClass":"CodecNotFoundException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/CodecRegistry.java","lineNumber":724,"sourceCode":"            }\n        }\n\n        // Look at the user-registered codecs next\n        for (TypeCodec<?> codec : codecs)\n        {\n            if ((cqlType == null || codec.accepts(cqlType)) && codec.accepts(value))\n            {\n                logger.trace(\"Already registered codec found: {}\", codec);\n                return (TypeCodec<T>) codec;\n            }\n        }\n        return createCodec(cqlType, value);\n    }\n\n    private <T> TypeCodec<T> createCodec(DataType cqlType, TypeToken<T> javaType)\n    {\n        TypeCodec<T> codec = maybeCreateCodec(cqlType, javaType);\n        if (codec == null) throw notFound(cqlType, javaType);\n        // double-check that the created codec satisfies the initial request\n        // this check can fail specially when creating codecs for collections\n        // e.g. if B extends A and there is a codec registered for A and\n        // we request a codec for List<B>, the registry would generate a codec for List<A>\n        if (!codec.accepts(cqlType) || (javaType != null && !codec.accepts(javaType)))\n            throw notFound(cqlType, javaType);\n        logger.trace(\"Codec created: {}\", codec);\n        return codec;\n    }\n\n    private <T> TypeCodec<T> createCodec(DataType cqlType, T value)\n    {\n        TypeCodec<T> codec = maybeCreateCodec(cqlType, value);\n        if (codec == null) throw notFound(cqlType, TypeToken.of(value.getClass()));\n        // double-check that the created codec satisfies the initial request\n        if ((cqlType != null && !codec.accepts(cqlType)) || !codec.accepts(value))\n            throw notFound(cqlType, TypeToken.of(value.getClass()));\n        logger.trace(\"Codec created: {}\", codec);","sourceCodeStart":706,"sourceCodeEnd":742,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/CodecRegistry.java#L706-L742","documentation":"CodecRegistry.createCodec(DataType, TypeToken) throws this when it cannot build a TypeCodec for the requested CQL type / Java type pair: either maybeCreateCodec returned null, or the freshly built codec fails the double-check codec.accepts(cqlType)/accepts(javaType). The double-check commonly fails for collections whose element Java type is a subclass of what the registry can serve.","triggerScenarios":"Calling codecRegistry.codecFor(cqlType, javaType) (or getCodec) with a type pair no registered codec accepts, e.g. a custom Java type with no registered codec, or a List<SubType> request where only a codec for List<BaseType> exists and the resulting codec fails the accepts() re-validation.","commonSituations":"Mapping a UDT or collection to a custom POJO without registering a codec; upgrading driver versions where type-token generics changed; requesting codecs for nested collections (map<text, list<udt>>) mapped to custom classes.","solutions":["Register a custom TypeCodec via CodecRegistry.getInstance().register(codec) covering the exact DataType/JavaType pair.","For collections, register an ElementCodec-based collection codec (e.g. TypeCodec.listOf(elementCodec)) so element mapping is explicit.","Verify the Java generic type matches the CQL type (e.g. List<Integer> for list<int>, not List<Integer> vs list<varint> surprises like BigInteger)."],"exampleFix":"// before\nTypeCodec<List<MyPojo>> c = registry.codecFor(cluster.getMetadata().newTupleType(...), new TypeToken<List<MyPojo>>(){});\n// after\nregistry.register(new MappingCodec<>(TypeCodec.listOf(udtCodec), new TypeToken<List<MyPojo>>(){}));","handlingStrategy":"try-catch","validationCode":"if (!registry.codecFor(cqlType).accepts(javaType)) System.err.println(\"no codec for \" + cqlType + \" <-> \" + javaType);","typeGuard":"boolean hasCodec(CodecRegistry r, DataType t, TypeToken<?> jt) { try { r.codecFor(t, jt); return true; } catch (Exception e) { return false; } }","tryCatchPattern":"try { TypeCodec<T> c = registry.codecFor(cqlType, javaType); ... } catch (InvalidTypeException | CodecNotFoundException e) { registerFallbackCodec(cqlType, javaType); }","preventionTips":["Register all custom codecs at application startup, before creating statements.","Keep Java generics aligned with CQL types (Integer/int, List not raw List).","Write a startup smoke test that requests a codec for every (type, javaType) pair you use."],"tags":["codec","driver","type-mapping","serialization"],"backgroundTag":"codec-not-found","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"}