alibaba/spring-cloud-alibaba · error · ParseException

Illegal characters for this position: '{}'

Error message

Illegal characters for this position: '{}'

What it means

Thrown in storeExpressionVals when a token begins with a letter A-Z but the field type is not MONTH or DAY_OF_WEEK (i.e. SECOND, MINUTE, HOUR, DAY_OF_MONTH, or YEAR). Letter tokens are only valid for month/weekday names; using one elsewhere is meaningless and the parser rejects it with ParseException 'Illegal characters for this position: \'<sub>\''.

Source

Thrown at spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-schedulerx/src/main/java/com/alibaba/cloud/scheduling/schedulerx/util/CronExpression.java:373

					if (c == '-') {
						i += 4;
						sub = s.substring(i, i + 3);
						eval = getDayOfWeekNumber(sub);
						Assert.isTrue(eval >= 0, "Invalid Day-of-Week value: '" + sub + "'");
					}
					else if (c == '#') {
						i += 4;
						nthdayOfWeek = Integer.parseInt(s.substring(i));
						Assert.isTrue(nthdayOfWeek > 0 && nthdayOfWeek < 6, "A numeric value between 1 and 5 must follow the '#' option");
					}
					else if (c == 'L') {
						lastdayOfWeek = true;
						i++;
					}
				}
			}
			else {
				throw new ParseException(
						"Illegal characters for this position: '" + sub + "'",
						i);
			}
			if (eval != -1) {
				incr = 1;
			}
			addToSet(sval, eval, incr, type);
			return (i + 3);
		}

		if (c == '?') {
			i++;
			if ((i + 1) < s.length()
					&& (s.charAt(i) != ' ' && s.charAt(i + 1) != '\t')) {
				throw new ParseException("Illegal character after '?': "
						+ s.charAt(i), i);
			}
			if (type != DAY_OF_WEEK && type != DAY_OF_MONTH) {

View on GitHub (pinned to 115d590110)

Solutions

  1. Ensure named tokens (JAN..DEC, SUN..SAT) appear only in the month or day-of-week positions respectively.
  2. Verify field order: second minute hour day-of-month month day-of-week [year].
  3. Replace stray letter tokens with valid numeric values.

Example fix

# before (month name in wrong position)
0 0 0 JAN * ?

# after (JAN belongs in the month field)
0 0 0 * JAN ?
Defensive patterns

Strategy: try-catch

Validate before calling

static String validateCron(String cron) throws ParseException {
    new com.alibaba.cloud.scheduling.schedulerx.util.CronExpression(cron);
    return cron;
}

Type guard

// named tokens only allowed in field index 4 (month) and 5 (day-of-week)
static boolean namedTokensInRightPlace(String[] f) {
    for (int i = 0; i < f.length; i++) {
        char c = f[i].charAt(0);
        if (c >= 'A' && c <= 'Z' && i != 4 && i != 5) return false;
    }
    return true;
}

Try / catch

try {
    new CronExpression(cron);
} catch (ParseException e) {
    // "Illegal characters for this position: 'ABC'"
    throw new IllegalArgumentException("Cron field ordering error in '" + cron + "'", e);
}

Prevention

When it happens

Trigger: A letter token in a numeric-only field, e.g. '0 ABC 0 * * ?' (ABC in the minute field) or '0 0 0 JAN * ?' where JAN is in the DAY_OF_MONTH position rather than MONTH. The else branch at CronExpression.java:371-374 fires.

Common situations: Field-ordering mistake (putting a month name in the wrong position); using 'AM'/'PM' style markers that Quartz does not support; a stray word leaking into the cron string.

Related errors


AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14). Data as JSON: /api/errors/69420749d9eef145. Report an issue: GitHub.