{"record":{"id":"69420749d9eef145","repo":"alibaba/spring-cloud-alibaba","slug":"illegal-characters-for-this-position","errorCode":null,"errorMessage":"Illegal characters for this position: '{}'","messagePattern":"Illegal characters for this position: '(.+?)'","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":373,"sourceCode":"\t\t\t\t\tif (c == '-') {\n\t\t\t\t\t\ti += 4;\n\t\t\t\t\t\tsub = s.substring(i, i + 3);\n\t\t\t\t\t\teval = getDayOfWeekNumber(sub);\n\t\t\t\t\t\tAssert.isTrue(eval >= 0, \"Invalid Day-of-Week value: '\" + sub + \"'\");\n\t\t\t\t\t}\n\t\t\t\t\telse if (c == '#') {\n\t\t\t\t\t\ti += 4;\n\t\t\t\t\t\tnthdayOfWeek = Integer.parseInt(s.substring(i));\n\t\t\t\t\t\tAssert.isTrue(nthdayOfWeek > 0 && nthdayOfWeek < 6, \"A numeric value between 1 and 5 must follow the '#' option\");\n\t\t\t\t\t}\n\t\t\t\t\telse if (c == 'L') {\n\t\t\t\t\t\tlastdayOfWeek = true;\n\t\t\t\t\t\ti++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new ParseException(\n\t\t\t\t\t\t\"Illegal characters for this position: '\" + sub + \"'\",\n\t\t\t\t\t\ti);\n\t\t\t}\n\t\t\tif (eval != -1) {\n\t\t\t\tincr = 1;\n\t\t\t}\n\t\t\taddToSet(sval, eval, incr, type);\n\t\t\treturn (i + 3);\n\t\t}\n\n\t\tif (c == '?') {\n\t\t\ti++;\n\t\t\tif ((i + 1) < s.length()\n\t\t\t\t\t&& (s.charAt(i) != ' ' && s.charAt(i + 1) != '\\t')) {\n\t\t\t\tthrow new ParseException(\"Illegal character after '?': \"\n\t\t\t\t\t\t+ s.charAt(i), i);\n\t\t\t}\n\t\t\tif (type != DAY_OF_WEEK && type != DAY_OF_MONTH) {","sourceCodeStart":355,"sourceCodeEnd":391,"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#L355-L391","documentation":"Thrown in storeExpressionVals when a token begins with a letter A-Z but the field type is not MONTH or DAY_OF_WEEK (i.e. SECOND, MINUTE, HOUR, DAY_OF_MONTH, or YEAR). Letter tokens are only valid for month/weekday names; using one elsewhere is meaningless and the parser rejects it with ParseException 'Illegal characters for this position: \\'<sub>\\''.","triggerScenarios":"A letter token in a numeric-only field, e.g. '0 ABC 0 * * ?' (ABC in the minute field) or '0 0 0 JAN * ?' where JAN is in the DAY_OF_MONTH position rather than MONTH. The else branch at CronExpression.java:371-374 fires.","commonSituations":"Field-ordering mistake (putting a month name in the wrong position); using 'AM'/'PM' style markers that Quartz does not support; a stray word leaking into the cron string.","solutions":["Ensure named tokens (JAN..DEC, SUN..SAT) appear only in the month or day-of-week positions respectively.","Verify field order: second minute hour day-of-month month day-of-week [year].","Replace stray letter tokens with valid numeric values."],"exampleFix":"# before (month name in wrong position)\n0 0 0 JAN * ?\n\n# after (JAN belongs in the month field)\n0 0 0 * JAN ?","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":"// named tokens only allowed in field index 4 (month) and 5 (day-of-week)\nstatic boolean namedTokensInRightPlace(String[] f) {\n    for (int i = 0; i < f.length; i++) {\n        char c = f[i].charAt(0);\n        if (c >= 'A' && c <= 'Z' && i != 4 && i != 5) return false;\n    }\n    return true;\n}","tryCatchPattern":"try {\n    new CronExpression(cron);\n} catch (ParseException e) {\n    // \"Illegal characters for this position: 'ABC'\"\n    throw new IllegalArgumentException(\"Cron field ordering error in '\" + cron + \"'\", e);\n}","preventionTips":["Memorise the 6-field order; named values go only in month (4th) and day-of-week (5th).","Trial-parse at config load."],"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"}