jeecgboot/JeecgBoot · error · ParseException
Invalid expression has too many terms: {expression}
Error message
Invalid expression has too many terms: {expression} What it means
Thrown by CronExpression's parser when the cron expression string contains more than 7 whitespace-separated tokens. A valid Quartz cron expression has exactly 6 or 7 fields: seconds, minutes, hours, day-of-month, month, day-of-week, and an optional year. Extra fields are invalid by definition. The error is a ParseException with the original expression embedded in the message.
Source
Thrown at jeecg-boot/jeecg-server-cloud/jeecg-visual/jeecg-cloud-xxljob/src/main/java/com/xxl/job/admin/business/scheduler/cron/CronExpression.java:483
nearestWeekdays = new TreeSet<>();
}
if (months == null) {
months = new TreeSet<>();
}
if (daysOfWeek == null) {
daysOfWeek = new TreeSet<>();
}
if (years == null) {
years = new TreeSet<>();
}
int exprOn = SECOND;
StringTokenizer exprsTok = new StringTokenizer(expression, " \t",
false);
if(exprsTok.countTokens() > 7) {
throw new ParseException("Invalid expression has too many terms: " + expression, -1);
}
while (exprsTok.hasMoreTokens() && exprOn <= YEAR) {
String expr = exprsTok.nextToken().trim();
// 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);
}
StringTokenizer vTok = new StringTokenizer(expr, ",");
while (vTok.hasMoreTokens()) {
String v = vTok.nextToken();
storeExpressionVals(0, v, exprOn);
}View on GitHub (pinned to 96fb33f5ec)
Solutions
- Count the whitespace-separated fields in your cron expression — it must be exactly 6 or 7.
- If migrating from Unix crontab (5 fields), prepend a seconds field: Unix '0 6 * * *' becomes Quartz '0 0 6 * * ?'.
- Remove any trailing command strings — Quartz cron expressions do not include the command to run.
- Trim and validate the expression programmatically before passing it to the scheduler.
Example fix
// before: 8-field expression (extra field) String cron = "0 0 12 * * ? 2024 EXTRA"; CronExpression expr = new CronExpression(cron); // after: valid 7-field expression (seconds min hour dom month dow year) String cron = "0 0 12 * * ? 2024"; CronExpression expr = new CronExpression(cron);
Defensive patterns
Strategy: validation
Validate before calling
// Validate cron expression field count before parsing
public void validateCronFieldCount(String expression) {
if (expression == null || expression.trim().isEmpty()) {
throw new IllegalArgumentException("Cron expression cannot be null or empty");
}
StringTokenizer tokenizer = new StringTokenizer(expression, " \t");
int count = tokenizer.countTokens();
if (count < 6 || count > 7) {
throw new IllegalArgumentException(
"Cron expression must have 6 or 7 fields, found " + count + ": " + expression);
}
} Type guard
// Check if expression has valid field count without parsing
public boolean hasValidCronFieldCount(String expression) {
if (expression == null || expression.trim().isEmpty()) return false;
int count = new StringTokenizer(expression, " \t").countTokens();
return count >= 6 && count <= 7;
} Try / catch
try {
CronExpression cron = new CronExpression(expression);
// use cron...
} catch (ParseException e) {
if (e.getMessage().contains("too many terms")) {
throw new IllegalArgumentException(
"Invalid cron expression: expected 6-7 fields but got more. Expression: " + expression, e);
}
throw e;
} Prevention
- Always count fields before constructing a CronExpression — valid Quartz cron has 6 or 7 fields.
- When migrating from Unix cron (5 fields), prepend a '0' seconds field.
- Do not include command strings in the cron expression — Quartz only takes the time pattern.
- Use a cron validation utility or library in your config/admin UI before saving the expression.
When it happens
Trigger: Providing a cron expression like '0 0 12 * * ? * extra' (8 fields). Copy-pasting a Unix crontab expression that has a username field prepended (e.g., 'root 0 6 * * * command'). Accidental extra spaces in a concatenation: "0 0 12" + " * * ? 2024 " + " extra". Using a 5-field Unix cron expression followed by a command string.
Common situations: Migrating from standard Unix cron (5 fields) to Quartz cron (6-7 fields) with incorrect format conversion. Copy-pasting cron expressions from tutorials that include non-standard fields. Dynamic expression building that accidentally appends extra segments. Confusing Spring's cron format (6 fields) with Quartz's (6-7 fields) and adding an extra separator.
Related errors
- Unexpected end of expression.
- Support for specifying 'L' with other days of the week is no
- Support for specifying multiple "nth" days is not implemente
- Support for specifying both a day-of-week AND a day-of-month
- Illegal cron expression format ({e})
AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14).
Data as JSON: /api/errors/01e6c0f474e7ea00.
Report an issue: GitHub.