{"record":{"id":"79f20901e13fa60a","repo":"chinabugotech/hutool","slug":"no-date-time-pattern-for-locale","errorCode":null,"errorMessage":"No date time pattern for locale: {}","messagePattern":"No date time pattern for locale: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/date/format/FormatCache.java","lineNumber":170,"sourceCode":"\t\t\ttry {\n\t\t\t\tDateFormat formatter;\n\t\t\t\tif (dateStyle == null) {\n\t\t\t\t\tformatter = DateFormat.getTimeInstance(timeStyle, locale);\n\t\t\t\t} else if (timeStyle == null) {\n\t\t\t\t\tformatter = DateFormat.getDateInstance(dateStyle, locale);\n\t\t\t\t} else {\n\t\t\t\t\tformatter = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);\n\t\t\t\t}\n\t\t\t\tpattern = ((SimpleDateFormat) formatter).toPattern();\n\t\t\t\tfinal String previous = C_DATE_TIME_INSTANCE_CACHE.putIfAbsent(key, pattern);\n\t\t\t\tif (previous != null) {\n\t\t\t\t\t// even though it doesn't matter if another thread put the pattern\n\t\t\t\t\t// it's still good practice to return the String instance that is\n\t\t\t\t\t// actually in the ConcurrentMap\n\t\t\t\t\tpattern = previous;\n\t\t\t\t}\n\t\t\t} catch (final ClassCastException ex) {\n\t\t\t\tthrow new IllegalArgumentException(\"No date time pattern for locale: \" + locale);\n\t\t\t}\n\t\t}\n\t\treturn pattern;\n\t}\n}\n","sourceCodeStart":152,"sourceCodeEnd":176,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/date/format/FormatCache.java#L152-L176","documentation":"FormatCache.getPatternForStyle asks the JDK for a localized DateFormat for a style+locale, then casts it to SimpleDateFormat to call toPattern(). If the returned DateFormat is not a SimpleDateFormat (the cast throws ClassCastException), the cache wraps it as IllegalArgumentException with the locale. This means the locale/provider cannot supply a SimpleDateFormat pattern for that style.","triggerScenarios":"Requesting a locale/style combo whose DateFormat.getInstance(...) returns a non-SimpleDateFormat implementation. Common with the JRE's Thai Buddhist locale (th_TH) using BuddhistCalendar-backed formats, some compact-number/extended locales, or when a custom LocaleProviderService / SPI is installed.","commonSituations":"Running with a non-default locale provider (e.g. CLDR vs HOST vs SPI), restricted locales under --limit-features, locales that yield non-Gregorian calendar-backed formats, or jlink'd runtimes missing locale data.","solutions":["Provide an explicit pattern instead of relying on style-based lookup (use getInstance(pattern) rather than getDateInstance(style, locale)).","Ensure the locale is supported by the active locale provider; avoid locales known to return non-SimpleDateFormat (or special-case them).","Ship full locale data in a custom/jlinked runtime (do not strip jdk.localedata)."],"exampleFix":"// before\nString p = FastDateFormat.getPatternForStyle(FULL, FULL, new Locale(\"th\",\"TH\"));\n// after - supply an explicit pattern\nFastDateFormat fdf = FastDateFormat.getInstance(\"yyyy-MM-dd HH:mm:ss\", timeZone, locale);","handlingStrategy":"validation","validationCode":"boolean localeUsesSimpleDateFormat(Integer dateStyle, Integer timeStyle, Locale l){\n  try { return DateFormat.getDateTimeInstance(dateStyle==null?0:dateStyle, timeStyle==null?0:timeStyle, l) instanceof SimpleDateFormat; }\n  catch(Exception e){ return false; }\n}","typeGuard":null,"tryCatchPattern":"try { FastDateFormat.getDateInstance(style, tz, locale); }\ncatch (IllegalArgumentException e){ if(e.getMessage().contains(\"No date time pattern for locale\")) { locale = Locale.US; } else throw e; }","preventionTips":["Prefer explicit patterns over style-based lookups for non-Gregorian locales.","Do not strip jdk.localedata in jlinked runtimes.","Document which locales your app supports for date formatting."],"tags":["date","locale","jvm-provider","argument","configuration"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}