{"record":{"id":"11702fdcd6af4e40","repo":"alibaba/canal","slug":"mismatch-class-type","errorCode":null,"errorMessage":"mismatch class type","messagePattern":"mismatch class type","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"client-adapter/hbase/src/main/java/com/alibaba/otter/canal/client/adapter/hbase/support/TypeUtil.java","lineNumber":135,"sourceCode":"            res = bytes[0];\n        } else if (BigDecimal.class == clazz) {\n            res = Bytes.toBigDecimal(bytes);\n        } else if (BigInteger.class == clazz) {\n            res = Bytes.toLong(bytes);\n        } else if (java.sql.Date.class == clazz) {\n            long ts = Bytes.toLong(bytes);\n            res = new java.sql.Date(ts);\n        } else if (Time.class == clazz) {\n            long ts = Bytes.toLong(bytes);\n            res = new Time(ts);\n        } else if (Timestamp.class == clazz) {\n            long ts = Bytes.toLong(bytes);\n            res = new Timestamp(ts);\n        } else if (Date.class == clazz) {\n            long ts = Bytes.toLong(bytes);\n            res = new Date(ts);\n        } else {\n            throw new IllegalArgumentException(\"mismatch class type\");\n        }\n        return (T) res;\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    public static <T> T toObject(byte[] bytes, Type type) {\n        if (bytes == null) {\n            return null;\n        }\n        Object res = null;\n        if (type == Type.STRING || type == Type.DEFAULT) {\n            res = Bytes.toString(bytes);\n        } else if (type == Type.INTEGER) {\n            if (bytes.length == Bytes.SIZEOF_INT) {\n                res = Bytes.toInt(bytes);\n            }\n        } else if (type == Type.LONG) {\n            if (bytes.length == Bytes.SIZEOF_LONG) {","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/client-adapter/hbase/src/main/java/com/alibaba/otter/canal/client/adapter/hbase/support/TypeUtil.java#L117-L153","documentation":"TypeUtil.toObject(byte[], Class<T>) deserializes bytes into a typed Java object for NATIVE mode. It handles String, primitives, BigDecimal/BigInteger, java.sql.Date/Time/Timestamp, Date, Byte. Any other Class falls through to 'throw new IllegalArgumentException(\"mismatch class type\")'. The class is simply not supported by this converter.","triggerScenarios":"Calling TypeUtil.toObject(bytes, SomeOtherClass.class) where SomeOtherClass is not in the supported set (e.g. a custom POJO, enum, LocalDate, Calendar, java.util.Calendar, etc.).","commonSituations":"Configuring an HBase mapping to deserialize a column into an unsupported Java type; custom code reading HBase via TypeUtil with a non-primitive class.","solutions":["Use one of the supported classes (String, Integer, Long, Short, Boolean, Float, Double, Byte, BigDecimal, BigInteger, java.sql.Date, Time, Timestamp, Date).","If you need an unsupported type, deserialize to String/byte[] first then convert in your own code.","For dates prefer java.util.Date or java.sql.Timestamp; avoid java.time types with this utility.","Store the value as a String and parse on read if no native type fits."],"exampleFix":"// before\nLocalDate d = TypeUtil.toObject(bytes, LocalDate.class); // unsupported\n\n// after\nTimestamp ts = TypeUtil.toObject(bytes, Timestamp.class);\nLocalDate d = ts.toLocalDateTime().toLocalDate();","handlingStrategy":"type-guard","validationCode":"private static final Set<Class<?>> SUPPORTED = Set.of(\n    String.class, Integer.class, int.class, Long.class, long.class,\n    Short.class, short.class, Boolean.class, boolean.class,\n    Float.class, float.class, Double.class, double.class,\n    Byte.class, byte.class, BigDecimal.class, BigInteger.class,\n    java.sql.Date.class, Time.class, Timestamp.class, Date.class);\nif (!SUPPORTED.contains(clazz)) {\n    throw new IllegalArgumentException(\"Unsupported class for TypeUtil.toObject: \" + clazz);\n}","typeGuard":"public static boolean isSupportedByTypeUtil(Class<?> clazz) {\n    return clazz == String.class || clazz == Integer.class || clazz == int.class\n        || clazz == Long.class || clazz == long.class || clazz == Short.class\n        || clazz == short.class || clazz == Boolean.class || clazz == boolean.class\n        || clazz == Float.class || clazz == float.class || clazz == Double.class\n        || clazz == double.class || clazz == Byte.class || clazz == byte.class\n        || clazz == BigDecimal.class || clazz == BigInteger.class\n        || clazz == java.sql.Date.class || clazz == Time.class\n        || clazz == Timestamp.class || clazz == Date.class;\n}","tryCatchPattern":"try {\n    T v = TypeUtil.toObject(bytes, clazz);\n} catch (IllegalArgumentException e) {\n    if (\"mismatch class type\".equals(e.getMessage())) {\n        logger.error(\"Class \" + clazz + \" not supported; use String/Date/primitive wrapper\");\n    }\n    throw e;\n}","preventionTips":["Restrict target types to the supported set.","For unsupported types, decode to String then convert.","Avoid java.time types with TypeUtil; convert from Timestamp."],"tags":["hbase-adapter","type-conversion","native-mode"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}