dianping/cat · error · ParseException

%sis illegal

Error message

%sis illegal

What it means

Thrown by DefaultFormat.parse when the ':'-suffixed length descriptor inside a format pattern is not a parsable integer. Patterns look like 'name:length' (e.g. 'md5:32'); the part after the colon must be a pure digit string. A java.text.ParseException (not RuntimeException) is thrown with the offending pattern appended.

Source

Thrown at cat-core/src/main/java/com/dianping/cat/config/DefaultFormat.java:44

	}

	@Override
	public String parse(String input) throws ParseException {
		String pattern = getPattern();
		String item = "";
		String describe = "";
		int index = pattern.indexOf(":");

		if (index != -1 && pattern.length() > index + 1) {
			item = pattern.substring(0, index).trim();
			describe = pattern.substring(index + 1).trim();
		}
		if (!describe.isEmpty()) {
			int length = 1;
			try {
				length = Integer.parseInt(describe);
			} catch (NumberFormatException e) {
				throw new ParseException(pattern + "is illegal", 0);
			}
			if (input.length() != length) {
				throw new ParseException("not match " + pattern, 0);
			}
		}
		if (pattern.equals("*")) {
			return input;
		} else if (item.equals("md5")) {
			char[] charArray = input.toCharArray();
			for (Character ch : charArray) {
				if (!Character.isDigit(ch) && !Character.isLowerCase(ch)) {
					return input;
				}
			}
		} else if (item.equals("number")) {
			char[] charArray = input.toCharArray();
			for (Character ch : charArray) {
				if (!Character.isDigit(ch)) {

View on GitHub (pinned to e815e74d4c)

Solutions

  1. Inspect the exact pattern string in the ParseException message and check the segment after the first ':'.
  2. Change the suffix to the expected field length (digits only), e.g. 'md5:32', 'number:1'.
  3. If no length constraint is wanted, drop the colon entirely: 'md5' instead of 'md5:x'.
  4. Validate format patterns at startup (regex like ^[^:]+(:\d+)?$) so bad config fails fast with a clear location.

Example fix

// before
format.parse("192.168.1.1", "ip:address"); // ParseException: ip:addressis illegal

// after
format.parse("192.168.1.1", "ip:15");
Defensive patterns

Strategy: validation

Validate before calling

private static final Pattern P = Pattern.compile("^[^:]+(:\\d+)?$");
if (!P.matcher(pattern).matches()) throw new IllegalArgumentException("Bad format pattern: " + pattern);

Try / catch

catch (ParseException e) { log.error("bad pattern {}", pattern); fail startup; }

Prevention

When it happens

Trigger: Calling DefaultFormat.parse(input, pattern) or the parse(Map,...) overload with a pattern whose suffix after ':' contains non-digits, e.g. 'city:abc', 'ip:32x', or a stray colon like 'type:'. Note 'type:' (empty describe) is tolerated; only a non-empty non-numeric describe triggers this.

Common situations: Hand-edited format strings in CAT content/config files (e.g. path format definitions for domain/ip/cluster rules) where someone writes a label or typo after the colon instead of a length; upgrading configs that changed pattern syntax.

Related errors


AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14). Data as JSON: /api/errors/7eea8a5f06b52530. Report an issue: GitHub.