chinabugotech/hutool · error · IllegalArgumentException

Format '{}' not supported

Error message

Format '{}' not supported

What it means

Thrown while compiling a FastDateParser pattern: the pattern contained a format letter (A-Z, a-z) that is not handled by getStrategy(). Only the letters supported by the switch (D,E,F,G,H,K,...) are accepted; any other alphabetic pattern character falls through to the default branch.

Source

Thrown at hutool-core/src/main/java/cn/hutool/core/date/format/FastDateParser.java:380

			setCalendar(parser, calendar, matcher.group(1));
			return true;
		}

		abstract void setCalendar(FastDateParser parser, Calendar cal, String value);
	}

	/**
	 * Obtain a Strategy given a field from a SimpleDateFormat pattern
	 *
	 * @param f                格式
	 * @param width            长度
	 * @param definingCalendar The calendar to obtain the short and long values
	 * @return The Strategy that will handle parsing for the field
	 */
	private Strategy getStrategy(final char f, final int width, final Calendar definingCalendar) {
		switch (f) {
			default:
				throw new IllegalArgumentException("Format '" + f + "' not supported");
			case 'D':
				return DAY_OF_YEAR_STRATEGY;
			case 'E':
				return getLocaleSpecificStrategy(Calendar.DAY_OF_WEEK, definingCalendar);
			case 'F':
				return DAY_OF_WEEK_IN_MONTH_STRATEGY;
			case 'G':
				return getLocaleSpecificStrategy(Calendar.ERA, definingCalendar);
			case 'H': // Hour in day (0-23)
				return HOUR_OF_DAY_STRATEGY;
			case 'K': // Hour in am/pm (0-11)
				return HOUR_STRATEGY;
			case 'M':
				return width >= 3 ? getLocaleSpecificStrategy(Calendar.MONTH, definingCalendar) : NUMBER_MONTH_STRATEGY;
			case 'S':
				return MILLISECOND_STRATEGY;
			case 'W':
				return WEEK_OF_MONTH_STRATEGY;

View on GitHub (pinned to 8870454b2a)

Solutions

  1. Replace the unsupported letter with a supported equivalent or remove it.
  2. Check the FastDateParser.getStrategy switch for the full list of supported letters before relying on a new pattern token.
  3. If the letter is required, fall back to java.text.SimpleDateFormat for that pattern.

Example fix

// before (Y = week-year, may be unsupported in this build)
FastDateFormat fdf = FastDateFormat.getInstance("YYYY-MM-dd");
// after
FastDateFormat fdf = FastDateFormat.getInstance("yyyy-MM-dd");
Defensive patterns

Strategy: validation

Validate before calling

private static final Set<Character> SUPPORTED = Set.of('y','M','d','H','k','K','h','m','s','S','E','u','D','F','w','W','a','G','z','Z','X');
void checkLetters(String p){ for(char c: p.toCharArray()) if(Character.isLetter(c) && !SUPPORTED.contains(c) ) throw new IllegalArgumentException("unsupported pattern letter "+c); }

Try / catch

try { FastDateFormat.getInstance(pattern); }
catch (IllegalArgumentException e){ if(e.getMessage().startsWith("Format '")) { /* swap letter */ } else throw e; }

Prevention

When it happens

Trigger: Using a pattern letter that SimpleDateFormat supports but FastDateParser does not (e.g. some rarely-used letters), or a typo in the pattern such as 'y' vs 'Y' (week-year) or stray letters. The error reports the offending single letter.

Common situations: Copying a pattern from Java docs that uses a letter Hutool's FastDateParser does not implement; locale-specific letters; mistyping pattern tokens.

Related errors


AI-assisted analysis of chinabugotech/hutool@8870454b2a (2026-08-14). Data as JSON: /api/errors/d9110a495fe2a0f2. Report an issue: GitHub.