{"record":{"id":"231946d229be4bdb","repo":"apache/cassandra","slug":"ignoring-codec-because-it-collides-with-previou","errorCode":null,"errorMessage":"Ignoring codec {} because it collides with previously registered codec {}","messagePattern":"Ignoring codec (.+?) because it collides with previously registered codec (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/java/org/apache/cassandra/cql3/functions/types/CodecRegistry.java","lineNumber":460,"sourceCode":"    /**\n     * Register the given codec with this registry.\n     *\n     * <p>This method will log a warning and ignore the codec if it collides with a previously\n     * registered one. Note that this check is not done in a completely thread-safe manner; codecs\n     * should typically be registered at application startup, not in a highly concurrent context (if a\n     * race condition occurs, the worst possible outcome is that no warning gets logged, and the codec\n     * gets registered but will never actually be used).\n     *\n     * @param newCodec The codec to add to the registry.\n     * @return this CodecRegistry (for method chaining).\n     */\n    public CodecRegistry register(TypeCodec<?> newCodec)\n    {\n        for (TypeCodec<?> oldCodec : BUILT_IN_CODECS)\n        {\n            if (oldCodec.accepts(newCodec.getCqlType()) && oldCodec.accepts(newCodec.getJavaType()))\n            {\n                logger.warn(\n                \"Ignoring codec {} because it collides with previously registered codec {}\",\n                newCodec,\n                oldCodec);\n                return this;\n            }\n        }\n        for (TypeCodec<?> oldCodec : codecs)\n        {\n            if (oldCodec.accepts(newCodec.getCqlType()) && oldCodec.accepts(newCodec.getJavaType()))\n            {\n                logger.warn(\n                \"Ignoring codec {} because it collides with previously registered codec {}\",\n                newCodec,\n                oldCodec);\n                return this;\n            }\n        }\n        CacheKey key = new CacheKey(newCodec.getCqlType(), newCodec.getJavaType());","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/CodecRegistry.java#L442-L478","documentation":"CodecRegistry refuses (with a warning, not an exception) to register a custom TypeCodec that accepts the same CQL type and Java type as one of the driver's built-in codecs; the new codec is ignored and the registry is returned unchanged. BUILT_IN_CODECS always win over user codecs.","triggerScenarios":"Calling codecRegistry.register(newCodec) where newCodec.getCqlType() and getJavaType() are both accepted by an existing built-in codec, e.g. registering a custom codec for (int <-> Integer).","commonSituations":"Users re-registering a codec for a primitive mapping that the Java driver already handles; copy-pasted codec tutorials for types already supported; driver-version upgrades that made a previously custom mapping built-in.","solutions":["Register a codec only for mappings not already built-in (check TypeCodec primitives/TypeCodec.enumIntCodec etc.)","If custom behavior is needed for a built-in mapping, bypass CodecRegistry and pass the codec explicitly to statement setters/getters","Remove the redundant registration call"],"exampleFix":"// before\nregistry.register(TypeCodec.blob()); // collides with built-in\n// after\n// no registration needed; built-in codec is used automatically","handlingStrategy":"validation","validationCode":"// Only register codecs for non-builtin mappings\nfunction needsRegistration(codec) {\n  const builtin = TypeCodec.primitiveMappings();\n  return !builtin.some(b => b.accepts(codec.getCqlType()) && b.accepts(codec.getJavaType()));\n}\nif (needsRegistration(myCodec)) registry.register(myCodec);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check built-in codec coverage before writing a custom codec","Keep codec registrations in one bootstrap module to spot duplicates","Re-audit custom codecs after driver upgrades"],"tags":["codec","driver","type-mapping"],"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"}