alibaba/spring-cloud-alibaba · error · ParseException
Support for specifying both a day-of-week AND a day-of-month
Error message
Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.
What it means
Thrown at the end of buildExpression when both day-of-month and day-of-week are explicitly specified, or both are '?'. Quartz semantics require exactly one of the two day fields to be constrained and the other to be '?' — you cannot say 'on the 1st AND on Monday' in one expression, nor '?' for both. The check at CronExpression.java:307-309 encodes this mutual exclusion.
Source
Thrown at spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-schedulerx/src/main/java/com/alibaba/cloud/scheduling/schedulerx/util/CronExpression.java:308
if (exprOn <= DAY_OF_WEEK) {
throw new ParseException("Unexpected end of expression.",
expression.length());
}
if (exprOn <= YEAR) {
storeExpressionVals(0, "*", YEAR);
}
final TreeSet<Integer> dow = getSet(DAY_OF_WEEK);
final TreeSet<Integer> dom = getSet(DAY_OF_MONTH);
// Copying the logic from the UnsupportedOperationException below
final boolean dayOfMSpec = !dom.contains(NO_SPEC);
final boolean dayOfWSpec = !dow.contains(NO_SPEC);
if (!dayOfMSpec || dayOfWSpec) {
if (!dayOfWSpec || dayOfMSpec) {
throw new ParseException(
"Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.", 0);
}
}
}
catch (final ParseException pe) {
throw pe;
}
catch (final Exception e) {
throw new ParseException("Illegal cron expression format ("
+ e.toString() + ")", 0);
}
}
protected int storeExpressionVals(final int pos, final String s, final int type)
throws ParseException {
int incr = 0;
int i = skipWhiteSpace(pos, s);View on GitHub (pinned to 115d590110)
Solutions
- Use '?' for the day field you do NOT want to constrain: '0 0 0 1 * ?' (day 1 of month) or '0 0 0 ? * MON' (every Monday).
- If you genuinely need both a day-of-month and a day-of-week condition, split into two triggers/jobs.
- Ensure you never use '?' for both day fields simultaneously.
Example fix
# before (both day fields specified -> invalid) 0 0 0 1 * MON # after (constrain only day-of-month, '?' for day-of-week) 0 0 0 1 * ?
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
// quick structural check: exactly one of DOM/DOW should be '?'
static boolean dayFieldsMutuallyExclusive(String[] f) {
boolean domQ = "?".equals(f[3]);
boolean dowQ = "?".equals(f[5]);
return domQ ^ dowQ; // exactly one is '?'
} Try / catch
try {
new CronExpression(cron);
} catch (ParseException e) {
// "Support for specifying both a day-of-week AND a day-of-month parameter is not implemented."
throw new IllegalArgumentException("Fix cron '" + cron + "': set one day field to '?'", e);
} Prevention
- Quartz rule of thumb: one day field gets a value, the other gets '?'.
- Avoid '*' for both day-of-month and day-of-week; replace one with '?'.
When it happens
Trigger: An expression like '0 0 0 1 * 1' (both DOM=1 and DOW=1, neither '?') or '0 0 0 ? * ?' (both '?'). dayOfMSpec/dayOfWSpec are derived from whether the set contains NO_SPEC (the '?' marker).
Common situations: Writing '0 0 0 1 * MON' intending 'the 1st and every Monday'; forgetting to put '?' for the unused day field; pasting a cron that uses '*' for both day fields (common in some cron dialects) instead of '?' for one.
Related errors
- Support for specifying 'L' and 'LW' with other days of the m
- Support for specifying 'L' with other days of the week is no
- Support for specifying multiple "nth" days is not implemente
- Unexpected end of expression.
- Illegal cron expression format ({})
AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14).
Data as JSON: /api/errors/af0fadb4e13cdc35.
Report an issue: GitHub.