{"record":{"id":"4fe71c10026b5e58","repo":"apache/dubbo","slug":"failed-to-parse-date-value-by-format-date-forma","errorCode":null,"errorMessage":"Failed to parse date {value} by format {DATE_FORMAT}, cause: {cause}","messagePattern":"Failed to parse date (.+?) by format (.+?), cause: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/utils/CompatibleTypeUtils.java","lineNumber":120,"sourceCode":"            }\n            if (type == Date.class\n                    || type == java.sql.Date.class\n                    || type == java.sql.Timestamp.class\n                    || type == java.sql.Time.class) {\n                try {\n                    Date date = new SimpleDateFormat(DATE_FORMAT).parse(string);\n                    if (type == java.sql.Date.class) {\n                        return new java.sql.Date(date.getTime());\n                    }\n                    if (type == java.sql.Timestamp.class) {\n                        return new java.sql.Timestamp(date.getTime());\n                    }\n                    if (type == java.sql.Time.class) {\n                        return new java.sql.Time(date.getTime());\n                    }\n                    return date;\n                } catch (ParseException e) {\n                    throw new IllegalStateException(\n                            \"Failed to parse date \" + value + \" by format \" + DATE_FORMAT + \", cause: \"\n                                    + e.getMessage(),\n                            e);\n                }\n            }\n            if (type == java.time.LocalDateTime.class) {\n                if (StringUtils.isEmpty(string)) {\n                    return null;\n                }\n                return LocalDateTime.parse(string);\n            }\n            if (type == java.time.LocalDate.class) {\n                if (StringUtils.isEmpty(string)) {\n                    return null;\n                }\n                return LocalDate.parse(string);\n            }\n            if (type == java.time.LocalTime.class) {","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CompatibleTypeUtils.java#L102-L138","documentation":"Thrown by CompatibleTypeUtils.compatibleTypeConvert when parsing a String into java.util.Date, java.sql.Date, java.sql.Timestamp, or java.sql.Time fails. The parser uses the fixed format 'yyyy-MM-dd HH:mm:ss'; a ParseException from SimpleDateFormat is wrapped in this IllegalStateException carrying the original message and cause.","triggerScenarios":"compatibleTypeConvert(stringValue, Date.class / java.sql.Date.class / Timestamp.class / Time.class) where stringValue does not match 'yyyy-MM-dd HH:mm:ss' — e.g. '2024-01-01', '01/01/2024 12:00', '2024-01-01T12:00:00Z' (ISO), or any locale-specific format.","commonSituations":"RPC/config deserialization of a Date field from a producer that used a different date format (ISO-8601, epoch millis, US locale); a config timestamp written as date-only without time; version change where the producer's serialization format shifted. Note java.time.LocalDateTime/LocalDate use their own parsing paths, not this format.","solutions":["Format the source string as 'yyyy-MM-dd HH:mm:ss' (24-hour, space separator, zero-padded).","If the value is epoch millis, convert it to a Long and target a long/Date via a numeric path instead.","If you need ISO-8601 or another format, parse it yourself before handing the value to compatibleTypeConvert, or use java.time types.","Inspect the chained ParseException cause for the exact unparseable position."],"exampleFix":"// before\nObject d = CompatibleTypeUtils.compatibleTypeConvert(\"2024-01-01\", Date.class); // throws\n\n// after\nObject d = CompatibleTypeUtils.compatibleTypeConvert(\"2024-01-01 00:00:00\", Date.class);\n// or parse the desired format yourself:\nDate d = new SimpleDateFormat(\"yyyy-MM-dd\").parse(\"2024-01-01\");","handlingStrategy":"validation","validationCode":"String s = /* ... */;\ntry {\n    new java.text.SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\").parse(s);\n} catch (java.text.ParseException pe) {\n    throw new IllegalArgumentException(\"Date value must match 'yyyy-MM-dd HH:mm:ss': \" + s, pe);\n}\nCompatibleTypeUtils.compatibleTypeConvert(s, Date.class);","typeGuard":"static boolean matchesDubboDateFormat(String s) {\n    if (s == null || s.length() != 19) return false;\n    try { new java.text.SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\").parse(s); return true; }\n    catch (java.text.ParseException e) { return false; }\n}","tryCatchPattern":"try {\n    Object d = CompatibleTypeUtils.compatibleTypeConvert(s, Date.class);\n} catch (IllegalStateException e) {\n    if (e.getCause() instanceof java.text.ParseException) {\n        // reformat the source or fall back to a custom parser\n    } else throw e;\n}","preventionTips":["Format date strings as 'yyyy-MM-dd HH:mm:ss' for Date/SQL date fields.","Use epoch millis + a numeric path, or java.time types, for other formats.","Inspect the chained ParseException for the exact unparseable position."],"tags":["type-conversion","rpc","date","parsing","configuration"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}