alibaba/spring-cloud-alibaba · error · ParseException

Illegal character after '?': {}

Error message

Illegal character after '?': {}

What it means

Thrown while parsing a '?' token: after consuming the '?' the parser checks the immediately following character; if it is not a space or tab (and more characters remain), it throws ParseException 'Illegal character after '?': <char>'. The '?' must stand alone as the entire field value.

Source

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

				}
			}
			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) {
				throw new ParseException(
						"'?' can only be specfied for Day-of-Month or Day-of-Week.",
						i);
			}
			if (type == DAY_OF_WEEK && !lastdayOfMonth) {
				final int val = daysOfMonth.last();
				if (val == NO_SPEC_INT) {
					throw new ParseException(
							"'?' can only be specfied for Day-of-Month -OR- Day-of-Week.",
							i);
				}
			}

			addToSet(NO_SPEC_INT, -1, 0, type);
			return i;

View on GitHub (pinned to 115d590110)

Solutions

  1. Make '?' the entire content of its field (no trailing characters).
  2. If you meant 'any value', use '*' instead of '?'; '?' specifically means 'no specific value' and is only for day-of-month/day-of-week.
  3. Validate at config load.

Example fix

# before
0 0 0 ?5 * *

# after
0 0 0 ? * *
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

// '?' must be a standalone field
static boolean qMarksAreStandalone(String[] f) {
    for (String tok : f) {
        if (tok.contains("?") && !tok.equals("?")) return false;
    }
    return true;
}

Try / catch

try {
    new CronExpression(cron);
} catch (ParseException e) {
    // "Illegal character after '?': 5"
    log.error("'?' must stand alone in cron '{}'", cron);
}

Prevention

When it happens

Trigger: A field like '?X' or '?,5' where '?' is followed by other characters, e.g. '0 0 0 ?5 * *'. The check at CronExpression.java:383-387 fires when (i+1 < length) and the char at i is not space and the next is not tab.

Common situations: Typing '?*' or '?5' thinking '?' can combine with other values; a stray character appended to '?'; copy-paste artefacts.

Related errors


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