{"record":{"id":"d9fd4027f0d9e395","repo":"alibaba/spring-cloud-alibaba","slug":"illegal-cron-expression-format","errorCode":null,"errorMessage":"Illegal cron expression format ({})","messagePattern":"Illegal cron expression format \\((.+?)\\)","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":317,"sourceCode":"\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);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcatch (final ParseException pe) {\n\t\t\tthrow pe;\n\t\t}\n\t\tcatch (final Exception e) {\n\t\t\tthrow new ParseException(\"Illegal cron expression format (\"\n\t\t\t\t\t+ e.toString() + \")\", 0);\n\t\t}\n\t}\n\n\tprotected int storeExpressionVals(final int pos, final String s, final int type)\n\t\t\tthrows ParseException {\n\n\t\tint incr = 0;\n\t\tint i = skipWhiteSpace(pos, s);\n\t\tif (i >= s.length()) {\n\t\t\treturn i;\n\t\t}\n\t\tchar c = s.charAt(i);\n\t\tif ((c >= 'A') && (c <= 'Z') && (!s.equals(\"L\")) && (!s.equals(\"LW\")) && (!s.matches(\"^L-[0-9]*[W]?\"))) {\n\t\t\tString sub = s.substring(i, i + 3);\n\t\t\tint sval = -1;\n\t\t\tint eval = -1;\n\t\t\tif (type == MONTH) {","sourceCodeStart":299,"sourceCodeEnd":335,"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#L299-L335","documentation":"The generic catch-all in buildExpression: any Exception thrown during parsing that is not itself a ParseException is wrapped as ParseException with message 'Illegal cron expression format (<exception.toString()>)'. It captures unanticipated parse failures (NumberFormat, index-out-of-bounds, etc.) so callers see a uniform ParseException.","triggerScenarios":"Any malformed cron that triggers a non-ParseException during storeExpressionVals or set parsing — e.g. a non-numeric character where a digit is expected ('0 0 0 X-Y * ?'), an empty field from double spaces collapsing oddly, or an out-of-range increment value. Caught at CronExpression.java:318-320.","commonSituations":"Typos like '0 0 0 /5 * ?' (leading slash), '0 0 0 1- * ?' (dangling dash), or copy-paste introducing invisible characters; values outside valid ranges that surface as NumberFormatException during Integer.parseInt.","solutions":["Inspect the wrapped exception in the message (the part in parentheses) to find the root cause (e.g. NumberFormatException: For input string \"X\").","Correct the offending field to valid cron syntax.","Run the cron through the CronExpression trial-parse validator at config load to get the exact error before deploy."],"exampleFix":"# before (dangling dash -> NumberFormatException wrapped)\n0 0 0 1- * ?\n\n# after\n0 0 0 1-31 * ?","handlingStrategy":"try-catch","validationCode":"static String validateCron(String cron) throws ParseException {\n    new com.alibaba.cloud.scheduling.schedulerx.util.CronExpression(cron);\n    return cron;\n}","typeGuard":null,"tryCatchPattern":"try {\n    new CronExpression(cron);\n} catch (ParseException e) {\n    // message: \"Illegal cron expression format (<root cause>)\"\n    log.error(\"Cannot parse cron '{}': {}\", cron, e.getMessage());\n    throw new IllegalArgumentException(\"Invalid cron '\" + cron + \"'\", e);\n}","preventionTips":["Always trial-parse user-supplied cron at config validation time.","Strip non-ASCII/invisible characters from pasted cron strings before parsing."],"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"}