{"record":{"id":"8d7a638e3ca58f56","repo":"alibaba/spring-cloud-alibaba","slug":"l-option-is-not-valid-here-pos","errorCode":null,"errorMessage":"'L' option is not valid here. (pos={})","messagePattern":"'L' option is not valid here\\. \\(pos=(.+?)\\)","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":531,"sourceCode":"\t\tint end = -1;\n\t\tint i = pos;\n\n\t\tif (i >= s.length()) {\n\t\t\taddToSet(val, end, -1, type);\n\t\t\treturn i;\n\t\t}\n\n\t\tchar c = s.charAt(pos);\n\n\t\tif (c == 'L') {\n\t\t\tif (type == DAY_OF_WEEK) {\n\t\t\t\tif (val < 1 || val > 7) {\n\t\t\t\t\tthrow new ParseException(\"Day-of-Week values must be between 1 and 7\", -1);\n\t\t\t\t}\n\t\t\t\tlastdayOfWeek = true;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new ParseException(\"'L' option is not valid here. (pos=\" + i + \")\", i);\n\t\t\t}\n\t\t\tfinal TreeSet<Integer> set = getSet(type);\n\t\t\tset.add(val);\n\t\t\ti++;\n\t\t\treturn i;\n\t\t}\n\n\t\tif (c == 'W') {\n\t\t\tif (type == DAY_OF_MONTH) {\n\t\t\t\tnearestWeekday = true;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new ParseException(\"'W' option is not valid here. (pos=\" + i + \")\", i);\n\t\t\t}\n\t\t\tif (val > 31) {\n\t\t\t\tthrow new ParseException(\"The 'W' option does not make sense with values larger than 31 (max number of days in a month)\", i);\n\t\t\t}\n\t\t\tfinal TreeSet<Integer> set = getSet(type);","sourceCodeStart":513,"sourceCodeEnd":549,"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#L513-L549","documentation":"Thrown in checkNext when 'L' follows a value but the current field is not DAY_OF_WEEK (guard at CronExpression.java:530-531). 'L' (last) is only valid in day-of-month (standalone) or day-of-week (as <n>L); here the '<n>L' form was used in some other field like minutes or hours.","triggerScenarios":"`new CronExpression(\"0 0L * * * ?\")` ('L' after 0 in minutes), or `0 0 5L * * ?` ('L' after 5 in hours). Any '<n>L' in seconds, minutes, hours, or month.","commonSituations":"Developer mistakenly appends 'L' to a time field thinking it means 'last', or a field-count error moves a weekday expression into the hours/minutes position.","solutions":["Use 'L' only in day-of-month (e.g. '0 0 0 L * ?') or as '<n>L' in day-of-week.","Remove 'L' from seconds/minutes/hours/month fields.","Recheck the six-field ordering."],"exampleFix":"// before\nnew CronExpression(\"0 0L * * * ?\");\n// after\nnew CronExpression(\"0 0 0 L * ?\"); // last day of month at 00:00","handlingStrategy":"validation","validationCode":"// 'L' may appear in day-of-month (standalone) or day-of-week (as <n>L) only.\nstatic boolean lUsedInValidField(String[] fields) {\n    // fields: seconds minutes hours dom month dow\n    if (fields.length < 6) return false;\n    if (fields[1].contains(\"L\") || fields[2].contains(\"L\") || fields[4].contains(\"L\")) return false;\n    if (fields[0].contains(\"L\")) return false;\n    return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n    CronExpression cron = new CronExpression(raw);\n} catch (ParseException e) {\n    throw new IllegalArgumentException(\"Invalid cron expression: \" + raw, e);\n}","preventionTips":["Use 'L' only in day-of-month or as '<n>L' in day-of-week.","Never append 'L' to seconds/minutes/hours/month values.","Recount fields so day expressions stay in their positions."],"tags":["cron","schedulerx","spring-cloud-alibaba","configuration","parsing","validation"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}