{"record":{"id":"bd7553e1d9e98a07","repo":"apache/dubbo","slug":"can-not-cast-to-date-value-value","errorCode":null,"errorMessage":"Can not cast to Date, value : '{value}'","messagePattern":"Can not cast to Date, value : '(.+?)'","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/utils/DateUtils.java","lineNumber":136,"sourceCode":"        if (value instanceof Date) {\n            return (Date) value;\n        }\n        if (value instanceof Calendar) {\n            return ((Calendar) value).getTime();\n        }\n        if (value.getClass() == Instant.class) {\n            return Date.from((Instant) value);\n        }\n        if (value instanceof TemporalAccessor) {\n            return Date.from(Instant.from((TemporalAccessor) value));\n        }\n        if (value instanceof Number) {\n            return new Date(((Number) value).longValue());\n        }\n        if (value instanceof CharSequence) {\n            return parse(value.toString());\n        }\n        throw new IllegalArgumentException(\"Can not cast to Date, value : '\" + value + \"'\");\n    }\n\n    public static Date parse(String value) {\n        if (value == null) {\n            return null;\n        }\n        String str = value.trim();\n        int len = str.length();\n        if (len == 0) {\n            return null;\n        }\n\n        boolean isIso = true;\n        boolean isNumeric = true;\n        boolean hasDate = false;\n        boolean hasTime = false;\n        for (int i = 0; i < len; i++) {\n            char c = str.charAt(i);","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/DateUtils.java#L118-L154","documentation":"Thrown by DateUtils.parse(Object) when the input value is not one of the supported types (Date, Calendar, Instant, TemporalAccessor, Number, or CharSequence). The library performs a type-dispatch to coerce the value to a Date, and any type that falls outside that set cannot be converted.","triggerScenarios":"Calling DateUtils.parse(value) where value is an arbitrary object such as a Boolean, Enum, custom POJO, or an array. The method has no catch-all conversion path, so unsupported runtime types reach the throw.","commonSituations":"Generic deserialization or configuration binding that pipes an unknown Object into DateUtils.parse without first narrowing the type; receiving a value from a loosely-typed Map or RPC payload.","solutions":["Pre-convert the value to a String, long/epoch-millis, or a known temporal type before calling DateUtils.parse","Add an instanceof check against the supported set (Date, Calendar, Instant, Number, CharSequence) and handle the else branch explicitly","If the value is a String in a non-standard format, register it via CUSTOM_FORMATTERS or parse it yourself and pass an Instant"],"exampleFix":"// before\nDate d = DateUtils.parse(someUnknownObject);\n// after\nif (someUnknownObject instanceof CharSequence || someUnknownObject instanceof Number) {\n    Date d = DateUtils.parse(someUnknownObject);\n} else {\n    throw new IllegalArgumentException(\"Unsupported date value: \" + someUnknownObject);\n}","handlingStrategy":"validation","validationCode":"Object v = ...;\nif (v == null || v instanceof java.util.Date || v instanceof java.util.Calendar\n        || v instanceof java.time.temporal.TemporalAccessor || v instanceof Number\n        || v instanceof CharSequence) {\n    java.util.Date d = org.apache.dubbo.common.utils.DateUtils.parse(v);\n} else {\n    throw new IllegalArgumentException(\"Unsupported value type for Date parse: \" + (v == null ? \"null\" : v.getClass()));\n}","typeGuard":"static boolean isDateParsable(Object v) {\n    return v == null || v instanceof java.util.Date || v instanceof java.util.Calendar\n        || v instanceof java.time.temporal.TemporalAccessor\n        || v instanceof Number || v instanceof CharSequence;\n}","tryCatchPattern":"try { Date d = DateUtils.parse(value); }\ncatch (IllegalArgumentException e) { /* value type unsupported; convert to String/long first */ }","preventionTips":["Type-narrow the value to String/Number/TemporalAccessor before calling parse","Avoid piping raw Object from loosely-typed maps into DateUtils"],"tags":["date","type-conversion","serialization"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}