{"record":{"id":"2e63c6206908885a","repo":"chinabugotech/hutool","slug":"unknown-class","errorCode":null,"errorMessage":"Unknown class: {}","messagePattern":"Unknown class: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/date/format/FastDatePrinter.java","lineNumber":310,"sourceCode":"\t// -----------------------------------------------------------------------\n\n\t/**\n\t * <p>\n\t * Formats a {@code Date}, {@code Calendar} or {@code Long} (milliseconds) object.\n\t * </p>\n\t *\n\t * @param obj the object to format\n\t * @return The formatted value.\n\t */\n\tString format(Object obj) {\n\t\tif (obj instanceof Date) {\n\t\t\treturn format((Date) obj);\n\t\t} else if (obj instanceof Calendar) {\n\t\t\treturn format((Calendar) obj);\n\t\t} else if (obj instanceof Long) {\n\t\t\treturn format(((Long) obj).longValue());\n\t\t} else {\n\t\t\tthrow new IllegalArgumentException(\"Unknown class: \" + (obj == null ? \"<null>\" : obj.getClass().getName()));\n\t\t}\n\t}\n\n\t@Override\n\tpublic String format(long millis) {\n\t\tfinal Calendar c = Calendar.getInstance(timeZone, locale);\n\t\tc.setTimeInMillis(millis);\n\t\treturn applyRulesToString(c);\n\t}\n\n\t@Override\n\tpublic String format(Date date) {\n\t\tfinal Calendar c = Calendar.getInstance(timeZone, locale);\n\t\tc.setTime(date);\n\t\treturn applyRulesToString(c);\n\t}\n\n\t@Override","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/date/format/FastDatePrinter.java#L292-L328","documentation":"FastDatePrinter.format(Object) only accepts Date, Calendar, or Long (epoch millis). Any other type, including null, throws IllegalArgumentException reporting the offending class name (or '<null>').","triggerScenarios":"Passing an Integer, String, BigInteger, java.time types (LocalDate/Instant), or null to a FastDateFormat.format(Object) overload; reflective/generic code that forwards arbitrary objects to the formatter.","commonSituations":"Mixing java.time (Instant/LocalDateTime) with the legacy Date API; passing epoch as int instead of long; null values from upstream optional fields.","solutions":["Convert the value to Date, Calendar, or long (millis) before formatting: Date.from(instant), Date.from(LocalDateTime.atZone(zone).toInstant()), or instant.toEpochMilli().","Guard against null and throw a domain-specific exception earlier.","Use DateUtil.formatDate / DateUtil.format with the correctly typed overload."],"exampleFix":"// before\nFastDateFormat fdf = FastDateFormat.getInstance(\"yyyy-MM-dd\");\nString s = fdf.format(java.time.LocalDate.now()); // throws\n// after\nString s = fdf.format(java.sql.Date.valueOf(java.time.LocalDate.now()));\n// or\nString s = fdf.format(Date.from(java.time.LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant()));","handlingStrategy":"type-guard","validationCode":"boolean isFormattable(Object o){ return o instanceof Date || o instanceof Calendar || o instanceof Long; }","typeGuard":"boolean canFormat(Object o){ return o != null && (o instanceof java.util.Date || o instanceof java.util.Calendar || o instanceof Long); }","tryCatchPattern":"try { s = fdf.format(obj); }\ncatch (IllegalArgumentException e){ if(e.getMessage().startsWith(\"Unknown class\")) { s = fdf.format(toDate(obj)); } else throw e; }","preventionTips":["Convert java.time values to Date/long before formatting.","Never pass null to format(Object); branch on null first.","Use the typed format(Date)/format(long) overloads."],"tags":["date","formatting","type-mismatch","argument"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}