alibaba/spring-cloud-alibaba · error · ParseException

Support for specifying multiple "nth" days is not implemente

Error message

Support for specifying multiple "nth" days is not implemented.

What it means

Thrown during parsing of the DAY_OF_WEEK field when a single token contains more than one '#' character. The '#' modifier means 'the Nth weekday of the month' (e.g. '5#2' = second Friday); Quartz forbids multiple '#' specifiers in one field, so the parser throws ParseException.

Source

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

			int exprOn = SECOND;

			final StringTokenizer exprsTok = new StringTokenizer(expression, " \t",
					false);

			while (exprsTok.hasMoreTokens() && exprOn <= YEAR) {
				final String expr = exprsTok.nextToken().trim();

				// throw an exception if L is used with other days of the month
				if (exprOn == DAY_OF_MONTH && expr.indexOf('L') != -1 && expr.length() > 1 && expr.contains(",")) {
					throw new ParseException("Support for specifying 'L' and 'LW' with other days of the month is not implemented", -1);
				}
				// throw an exception if L is used with other days of the week
				if (exprOn == DAY_OF_WEEK && expr.indexOf('L') != -1 && expr.length() > 1 && expr.contains(",")) {
					throw new ParseException("Support for specifying 'L' with other days of the week is not implemented", -1);
				}
				if (exprOn == DAY_OF_WEEK && expr.indexOf('#') != -1 && expr.indexOf('#', expr.indexOf('#') + 1) != -1) {
					throw new ParseException("Support for specifying multiple \"nth\" days is not implemented.", -1);
				}

				final StringTokenizer vTok = new StringTokenizer(expr, ",");
				while (vTok.hasMoreTokens()) {
					final String v = vTok.nextToken();
					storeExpressionVals(0, v, exprOn);
				}

				exprOn++;
			}

			if (exprOn <= DAY_OF_WEEK) {
				throw new ParseException("Unexpected end of expression.",
						expression.length());
			}

			if (exprOn <= YEAR) {
				storeExpressionVals(0, "*", YEAR);

View on GitHub (pinned to 115d590110)

Solutions

  1. Use one '#' per trigger and create multiple triggers for multiple nth-weekday rules.
  2. Correct the token to a single '<dow>#<n>' (n between 1 and 5).
  3. Validate the cron expression at config load.

Example fix

# before (invalid: two '#' in one field)
0 0 0 ? * 5#2#3

# after (two triggers, one nth-day each)
0 0 0 ? * 5#2
0 0 0 ? * 5#3
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

// day-of-week token must contain at most one '#'
static boolean atMostOneHash(String dowToken) {
    return dowToken.indexOf('#') == dowToken.lastIndexOf('#');
}

Try / catch

try {
    new CronExpression(cron);
} catch (ParseException e) {
    // "Support for specifying multiple \"nth\" days is not implemented."
    throw new IllegalArgumentException("Invalid cron '" + cron + "'", e);
}

Prevention

When it happens

Trigger: A day-of-week token like '5#2#3' (two '#' in one field). The check at CronExpression.java:276-278 fires when indexOf('#')!=-1 and a second '#' exists after the first.

Common situations: Attempting 'the 2nd and 3rd Friday' as '5#2#3' instead of two triggers; a typo inserting an extra '#'; malformed generated cron from a UI.

Related errors


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