{"record":{"id":"4f284481cbbbac93","repo":"chinabugotech/hutool","slug":"unsupported-target-date-type","errorCode":null,"errorMessage":"Unsupported target Date type: {}","messagePattern":"Unsupported target Date type: (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/convert/impl/DateConverter.java","lineNumber":114,"sourceCode":"\tprivate java.util.Date wrap(DateTime date) {\n\t\t// 返回指定类型\n\t\tif (java.util.Date.class == targetType) {\n\t\t\treturn date.toJdkDate();\n\t\t}\n\t\tif (DateTime.class == targetType) {\n\t\t\treturn date;\n\t\t}\n\t\tif (java.sql.Date.class == targetType) {\n\t\t\treturn date.toSqlDate();\n\t\t}\n\t\tif (java.sql.Time.class == targetType) {\n\t\t\treturn new java.sql.Time(date.getTime());\n\t\t}\n\t\tif (java.sql.Timestamp.class == targetType) {\n\t\t\treturn date.toTimestamp();\n\t\t}\n\n\t\tthrow new UnsupportedOperationException(StrUtil.format(\"Unsupported target Date type: {}\", this.targetType.getName()));\n\t}\n\n\t/**\n\t * java.util.Date转为子类型\n\t *\n\t * @param mills Date\n\t * @return 目标类型对象\n\t */\n\tprivate java.util.Date wrap(long mills) {\n\t\tif(GlobalCustomFormat.FORMAT_SECONDS.equals(this.format)){\n\t\t\t// Unix时间戳\n\t\t\treturn DateUtil.date(mills * 1000);\n\t\t}\n\n\t\t// 返回指定类型\n\t\tif (java.util.Date.class == targetType) {\n\t\t\treturn new java.util.Date(mills);\n\t\t}","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/convert/impl/DateConverter.java#L96-L132","documentation":"DateConverter.wrap(DateTime) only returns java.util.Date, DateTime, java.sql.Date, java.sql.Time, java.sql.Timestamp. Any other java.util.Date subclass as targetType throws UnsupportedOperationException.","triggerScenarios":"Constructing new DateConverter(MyCustomDate.class) where MyCustomDate extends java.util.Date but is not one of the five supported subtypes; converting from a TemporalAccessor/Calendar/DateTime source.","commonSituations":"Using third-party date types (e.g. Joda DateTime that extends java.util.Date), custom date wrappers.","solutions":["Target one of the supported subtypes (typically java.util.Date) and adapt afterwards.","Register a custom Converter for your date subtype.","Convert to java.util.Date then construct your subtype from getTime()."],"exampleFix":"// before\nDateConverter c = new DateConverter(MyDate.class);\n\n// after - target base type then adapt\nDate base = new DateConverter(Date.class).convert(value, null);\nMyDate md = new MyDate(base.getTime());","handlingStrategy":"validation","validationCode":"private static final Set<Class<?>> SUPPORTED = Set.of(\n        java.util.Date.class, DateTime.class,\n        java.sql.Date.class, java.sql.Time.class, java.sql.Timestamp.class);\nif (!SUPPORTED.contains(targetType)) {\n    targetType = java.util.Date.class; // fall back to base type\n}\nnew DateConverter(targetType);","typeGuard":null,"tryCatchPattern":"try {\n    return new DateConverter(targetType).convert(value, null);\n} catch (UnsupportedOperationException e) {\n    if (e.getMessage().startsWith(\"Unsupported target Date type\")) {\n        return new DateConverter(java.util.Date.class).convert(value, null);\n    }\n    throw e;\n}","preventionTips":["Restrict target types to the five supported Date subtypes.","Convert to java.util.Date then build your custom subtype from getTime()."],"tags":["convert","date","unsupported-type"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}