{"record":{"id":"180461ffb8f96351","repo":"apache/cassandra","slug":"cannot-convert-value-s-of-type-s","errorCode":null,"errorMessage":"Cannot convert value %s of type %s","messagePattern":"Cannot convert value (.+?) of type (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/utils/ByteBufferUtil.java","lineNumber":661,"sourceCode":"            }\n            // decompose/serializer doesn't use the isMultiCell, so safe to do this\n            return MapType.getInstance(BytesType.instance, BytesType.instance, false).decompose(bbs);\n        }\n        else if (obj instanceof Set)\n        {\n            Set<?> set = (Set<?>) obj;\n            // convert subtypes to BB\n            Set<ByteBuffer> bbs = new LinkedHashSet<>();\n            for (Object o : set)\n                if (!bbs.add(objectToBytes(o)))\n                    throw new IllegalStateException(\"Object \" + o + \" maps to a buffer that already exists in the set\");\n            // decompose/serializer doesn't use the isMultiCell, so safe to do this\n            return SetType.getInstance(BytesType.instance, false).decompose(bbs);\n        }\n        else if (obj instanceof Date)\n            return TimestampType.instance.decompose((Date) obj);\n        else\n            throw new IllegalArgumentException(String.format(\"Cannot convert value %s of type %s\",\n                                                             obj,\n                                                             obj.getClass()));\n    }\n\n    public static ByteBuffer bytes(byte b)\n    {\n        return ByteBuffer.allocate(1).put(0, b);\n    }\n\n    public static ByteBuffer bytes(short s)\n    {\n        return ByteBuffer.allocate(2).putShort(0, s);\n    }\n\n    public static ByteBuffer bytes(int i)\n    {\n        return ByteBuffer.allocate(4).putInt(0, i);\n    }","sourceCodeStart":643,"sourceCodeEnd":679,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/utils/ByteBufferUtil.java#L643-L679","documentation":"IllegalStateException from ByteBufferUtil.objectToBytes' fallback branch: the object's runtime type is not one of the supported Java/serialized types (Number, Date, UUID, Collection subtypes handled above), so no known conversion to a ByteBuffer exists. This is a generic terminal guard for unsupported input types in internal object-to-buffer conversion.","triggerScenarios":"Passing an unsupported object (e.g., a POJO, a custom enum instance, or any type without a conversion branch) into objectToBytes via UDT/collection value construction.","commonSituations":"Application code stuffing arbitrary Java objects into UDT fields; missing a case for a type after adding new custom types.","solutions":["Convert the value to a supported type (ByteBuffer, String, number, Date, Boolean) before passing it","Serialize the POJO yourself to a ByteBuffer using an appropriate type codec","Extend your value-building code to map unsupported types explicitly","Check which field/type of your UDT value is the offending class"],"exampleFix":"// before\nudt.setObject(\"field\", myPojo); // IllegalArgumentException\n// after\nudt.setObject(\"field\", myPojo.toString()); // or serialize to ByteBuffer via codec","handlingStrategy":"type-guard","validationCode":"// whitelist supported types before calling objectToBytes\nboolean supported = obj instanceof Map || obj instanceof Set || obj instanceof Date\n    || obj instanceof ByteBuffer || obj instanceof String || obj instanceof Number\n    || obj instanceof Boolean;\nif (!supported) throw new IllegalArgumentException(\"unsupported UDT field type: \" + obj.getClass());","typeGuard":"static boolean isConvertible(Object o) {\n    return o instanceof Map || o instanceof Set || o instanceof Date\n        || o instanceof ByteBuffer || o instanceof String\n        || o instanceof Number || o instanceof Boolean;\n}","tryCatchPattern":"try {\n    ByteBuffer bb = ByteBufferUtil.objectToBytes(value);\n} catch (IllegalArgumentException e) {\n    // serialize manually with the field's codec\n}","preventionTips":["Map POJOs to supported types or explicit ByteBuffers before UDT construction","Add a unit test covering every field type in your UDTs","Keep a type-mapping table for driver-to-Cassandra conversions"],"tags":["serialization","type-mismatch","bytebuffer"],"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"}