{"record":{"id":"3377a53a99bc20cc","repo":"chinabugotech/hutool","slug":"unsupported-target-type","errorCode":null,"errorMessage":"Unsupported target type: {}","messagePattern":"Unsupported target type: (.+?)","errorType":"exception","errorClass":"ConvertException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/convert/impl/PrimitiveConverter.java","lineNumber":90,"sourceCode":"\t\tif (byte.class == primitiveClass) {\n\t\t\treturn ObjectUtil.defaultIfNull(NumberConverter.convert(value, Byte.class, toStringFunc), 0);\n\t\t} else if (short.class == primitiveClass) {\n\t\t\treturn ObjectUtil.defaultIfNull(NumberConverter.convert(value, Short.class, toStringFunc), 0);\n\t\t} else if (int.class == primitiveClass) {\n\t\t\treturn ObjectUtil.defaultIfNull(NumberConverter.convert(value, Integer.class, toStringFunc), 0);\n\t\t} else if (long.class == primitiveClass) {\n\t\t\treturn ObjectUtil.defaultIfNull(NumberConverter.convert(value, Long.class, toStringFunc), 0);\n\t\t} else if (float.class == primitiveClass) {\n\t\t\treturn ObjectUtil.defaultIfNull(NumberConverter.convert(value, Float.class, toStringFunc), 0);\n\t\t} else if (double.class == primitiveClass) {\n\t\t\treturn ObjectUtil.defaultIfNull(NumberConverter.convert(value, Double.class, toStringFunc), 0);\n\t\t} else if (char.class == primitiveClass) {\n\t\t\treturn Convert.convert(Character.class, value);\n\t\t} else if (boolean.class == primitiveClass) {\n\t\t\treturn Convert.convert(Boolean.class, value);\n\t\t}\n\n\t\tthrow new ConvertException(\"Unsupported target type: {}\", primitiveClass);\n\t}\n}\n","sourceCodeStart":72,"sourceCodeEnd":93,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/convert/impl/PrimitiveConverter.java#L72-L93","documentation":"Thrown at the end of the static PrimitiveConverter.convert() method when primitiveClass does not match any of the eight supported primitive types (byte, short, int, long, float, double, char, boolean). In normal usage this is nearly unreachable because the constructor pre-validates isPrimitive(), but it can fire if the static convert() method is called directly with an unsupported primitive type such as void.class.","triggerScenarios":"Calling PrimitiveConverter.convert(value, void.class, toStringFunc) directly. Subclassing PrimitiveConverter and bypassing the constructor check, then reaching convertInternal with a targetType like void.class. The Java primitive void.class is technically primitive but has no conversion path here.","commonSituations":"Reflective code that enumerates all primitive types and attempts conversion for each, including void.class. Unit tests that exercise the converter with the full Primitive enum. Framework code that derives primitiveClass from a Method return type that happens to be void.","solutions":["Exclude void.class from any loop that feeds types into PrimitiveConverter.convert() — it is primitive but unsupported.","Guard with an explicit check: if (primitiveClass == void.class) skip or handle separately.","Use Convert.convert() (the high-level facade) instead of calling PrimitiveConverter.convert() directly, so the registry routes correctly.","If subclassing, ensure the constructor's isPrimitive() validation is preserved."],"exampleFix":"// before\nPrimitiveConverter.convert(value, void.class, Object::toString); // throws\n\n// after\nif (primitiveClass != void.class) {\n    PrimitiveConverter.convert(value, primitiveClass, Object::toString);\n}","handlingStrategy":"validation","validationCode":"if (primitiveClass == void.class) {\n    return null; // or throw with a meaningful message\n}\nPrimitiveConverter.convert(value, primitiveClass, Object::toString);","typeGuard":"static boolean isConvertiblePrimitive(Class<?> clazz) {\n    return clazz == byte.class || clazz == short.class || clazz == int.class\n        || clazz == long.class || clazz == float.class || clazz == double.class\n        || clazz == char.class || clazz == boolean.class;\n}","tryCatchPattern":"try {\n    return PrimitiveConverter.convert(value, primitiveClass, toStringFunc);\n} catch (ConvertException e) {\n    // handle unsupported primitive type (e.g., void.class)\n    return defaultValue;\n}","preventionTips":["Never pass void.class to PrimitiveConverter.convert().","Prefer using the constructor-validated instance path over calling the static convert() directly.","Filter void.class out of any reflective type iteration before conversion."],"tags":["convert","primitive-type","void","convert-exception"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}