{"record":{"id":"01e6c0f474e7ea00","repo":"jeecgboot/JeecgBoot","slug":"invalid-expression-has-too-many-terms-expression","errorCode":null,"errorMessage":"Invalid expression has too many terms: {expression}","messagePattern":"Invalid expression has too many terms: (.+?)","errorType":"exception","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"jeecg-boot/jeecg-server-cloud/jeecg-visual/jeecg-cloud-xxljob/src/main/java/com/xxl/job/admin/business/scheduler/cron/CronExpression.java","lineNumber":483,"sourceCode":"                nearestWeekdays = new TreeSet<>();\n            }\n            if (months == null) {\n                months = new TreeSet<>();\n            }\n            if (daysOfWeek == null) {\n                daysOfWeek = new TreeSet<>();\n            }\n            if (years == null) {\n                years = new TreeSet<>();\n            }\n\n            int exprOn = SECOND;\n\n            StringTokenizer exprsTok = new StringTokenizer(expression, \" \\t\",\n                    false);\n\n            if(exprsTok.countTokens() > 7) {\n                throw new ParseException(\"Invalid expression has too many terms: \" + expression, -1);\n            }\n\n            while (exprsTok.hasMoreTokens() && exprOn <= YEAR) {\n                String expr = exprsTok.nextToken().trim();\n\n                // throw an exception if L is used with other days of the week\n                if(exprOn == DAY_OF_WEEK && expr.indexOf('L') != -1 && expr.length() > 1  && expr.contains(\",\")) {\n                    throw new ParseException(\"Support for specifying 'L' with other days of the week is not implemented\", -1);\n                }\n                if(exprOn == DAY_OF_WEEK && expr.indexOf('#') != -1 && expr.indexOf('#', expr.indexOf('#') +1) != -1) {\n                    throw new ParseException(\"Support for specifying multiple \\\"nth\\\" days is not implemented.\", -1);\n                }\n\n                StringTokenizer vTok = new StringTokenizer(expr, \",\");\n                while (vTok.hasMoreTokens()) {\n                    String v = vTok.nextToken();\n                    storeExpressionVals(0, v, exprOn);\n                }","sourceCodeStart":465,"sourceCodeEnd":501,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-server-cloud/jeecg-visual/jeecg-cloud-xxljob/src/main/java/com/xxl/job/admin/business/scheduler/cron/CronExpression.java#L465-L501","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: 8-field expression (extra field)\nString cron = \"0 0 12 * * ? 2024 EXTRA\";\nCronExpression expr = new CronExpression(cron);\n\n// after: valid 7-field expression (seconds min hour dom month dow year)\nString cron = \"0 0 12 * * ? 2024\";\nCronExpression expr = new CronExpression(cron);","handlingStrategy":"validation","validationCode":"// Validate cron expression field count before parsing\npublic void validateCronFieldCount(String expression) {\n    if (expression == null || expression.trim().isEmpty()) {\n        throw new IllegalArgumentException(\"Cron expression cannot be null or empty\");\n    }\n    StringTokenizer tokenizer = new StringTokenizer(expression, \" \\t\");\n    int count = tokenizer.countTokens();\n    if (count < 6 || count > 7) {\n        throw new IllegalArgumentException(\n            \"Cron expression must have 6 or 7 fields, found \" + count + \": \" + expression);\n    }\n}","typeGuard":"// Check if expression has valid field count without parsing\npublic boolean hasValidCronFieldCount(String expression) {\n    if (expression == null || expression.trim().isEmpty()) return false;\n    int count = new StringTokenizer(expression, \" \\t\").countTokens();\n    return count >= 6 && count <= 7;\n}","tryCatchPattern":"try {\n    CronExpression cron = new CronExpression(expression);\n    // use cron...\n} catch (ParseException e) {\n    if (e.getMessage().contains(\"too many terms\")) {\n        throw new IllegalArgumentException(\n            \"Invalid cron expression: expected 6-7 fields but got more. Expression: \" + expression, e);\n    }\n    throw e;\n}","preventionTips":["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."],"tags":["cron","quartz","scheduling","xxl-job","validation"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}