{"record":{"id":"8625a42a53aaed42","repo":"alibaba/spring-cloud-alibaba","slug":"unexpected-end-of-expression","errorCode":null,"errorMessage":"Unexpected end of expression.","messagePattern":"Unexpected end of expression\\.","errorType":"exception","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-schedulerx/src/main/java/com/alibaba/cloud/scheduling/schedulerx/util/CronExpression.java","lineNumber":291,"sourceCode":"\t\t\t\t// throw an exception if L is used with other days of the week\n\t\t\t\tif (exprOn == DAY_OF_WEEK && expr.indexOf('L') != -1 && expr.length() > 1 && expr.contains(\",\")) {\n\t\t\t\t\tthrow new ParseException(\"Support for specifying 'L' with other days of the week is not implemented\", -1);\n\t\t\t\t}\n\t\t\t\tif (exprOn == DAY_OF_WEEK && expr.indexOf('#') != -1 && expr.indexOf('#', expr.indexOf('#') + 1) != -1) {\n\t\t\t\t\tthrow new ParseException(\"Support for specifying multiple \\\"nth\\\" days is not implemented.\", -1);\n\t\t\t\t}\n\n\t\t\t\tfinal StringTokenizer vTok = new StringTokenizer(expr, \",\");\n\t\t\t\twhile (vTok.hasMoreTokens()) {\n\t\t\t\t\tfinal String v = vTok.nextToken();\n\t\t\t\t\tstoreExpressionVals(0, v, exprOn);\n\t\t\t\t}\n\n\t\t\t\texprOn++;\n\t\t\t}\n\n\t\t\tif (exprOn <= DAY_OF_WEEK) {\n\t\t\t\tthrow new ParseException(\"Unexpected end of expression.\",\n\t\t\t\t\t\texpression.length());\n\t\t\t}\n\n\t\t\tif (exprOn <= YEAR) {\n\t\t\t\tstoreExpressionVals(0, \"*\", YEAR);\n\t\t\t}\n\n\t\t\tfinal TreeSet<Integer> dow = getSet(DAY_OF_WEEK);\n\t\t\tfinal TreeSet<Integer> dom = getSet(DAY_OF_MONTH);\n\n\t\t\t// Copying the logic from the UnsupportedOperationException below\n\t\t\tfinal boolean dayOfMSpec = !dom.contains(NO_SPEC);\n\t\t\tfinal boolean dayOfWSpec = !dow.contains(NO_SPEC);\n\n\t\t\tif (!dayOfMSpec || dayOfWSpec) {\n\t\t\t\tif (!dayOfWSpec || dayOfMSpec) {\n\t\t\t\t\tthrow new ParseException(\n\t\t\t\t\t\t\t\"Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.\", 0);","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/alibaba/spring-cloud-alibaba/blob/115d5901102009492e05d5ec18c3f79cad4077d0/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-schedulerx/src/main/java/com/alibaba/cloud/scheduling/schedulerx/util/CronExpression.java#L273-L309","documentation":"Thrown at the end of buildExpression if fewer than six whitespace-separated fields were parsed (exprOn, the field counter, did not advance past DAY_OF_WEEK). This CronExpression expects six mandatory fields — second minute hour day-of-month month day-of-week — with an optional seventh (year). Providing too few fields yields ParseException 'Unexpected end of expression.'.","triggerScenarios":"A cron with fewer than six fields, e.g. traditional 5-field Unix cron '0 9 * * *' (missing seconds and the '?' for one day field). The check at CronExpression.java:290-293 throws when exprOn <= DAY_OF_WEEK after consuming all tokens.","commonSituations":"Pasting a 5-field Linux crontab entry into a Quartz/SchedulerX config; trailing whitespace trimming that merges fields; an expression truncated by a templating or escaping bug.","solutions":["Rewrite the cron in 6-field Quartz form: prepend a seconds field and ensure both day-of-month and day-of-week fields are present (use '?' for the one you don't constrain).","For 'daily at 09:00' use '0 0 9 * * ?' (sec=0 min=0 hour=9 dom=* month=* dow=?).","Validate field count == 6 or 7 before parsing."],"exampleFix":"# before (5-field Unix cron -> too few fields)\n0 9 * * *\n\n# after (6-field Quartz form)\n0 0 9 * * ?","handlingStrategy":"try-catch","validationCode":"static void requireSixOrSevenFields(String cron) {\n    int n = cron.trim().split(\"\\\\s+\").length;\n    if (n < 6 || n > 7) {\n        throw new IllegalArgumentException(\n            \"cron must have 6 or 7 fields, got \" + n);\n    }\n}\n// then new com.alibaba.cloud.scheduling.schedulerx.util.CronExpression(cron)","typeGuard":null,"tryCatchPattern":"try {\n    new CronExpression(cron);\n} catch (ParseException e) {\n    // \"Unexpected end of expression.\" -> too few fields\n    log.error(\"Cron '{}' has too few fields (need 6): {}\", cron, e.getMessage());\n}","preventionTips":["Remember SchedulerX/Quartz cron requires a leading seconds field that Unix cron lacks.","Add a field-count assertion in your cron-validation step."],"tags":["java","schedulerx","cron","parsing","validation"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}