{"record":{"id":"594b58fa8bbbce63","repo":"jeecgboot/JeecgBoot","slug":"illegal-characters-for-this-position-sub","errorCode":null,"errorMessage":"Illegal characters for this position: '{sub}'","messagePattern":"Illegal characters for this position: '(.+?)'","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":601,"sourceCode":"                        try {\n                            i += 4;\n                            nthDayOfWeek = Integer.parseInt(s.substring(i));\n                            if (nthDayOfWeek < 1 || nthDayOfWeek > 5) {\n                                throw new Exception();\n                            }\n                        } catch (Exception e) {\n                            throw new ParseException(\n                                    \"A numeric value between 1 and 5 must follow the '#' option\",\n                                    i);\n                        }\n                    } else if (c == 'L') {\n                        lastDayOfWeek = true;\n                        i++;\n                    }\n                }\n\n            } else {\n                throw new ParseException(\n                        \"Illegal characters for this position: '\" + sub + \"'\",\n                        i);\n            }\n            if (eval != -1) {\n                incr = 1;\n            }\n            addToSet(sval, eval, incr, type);\n            return (i + 3);\n        }\n\n        if (c == '?') {\n            i++;\n            if ((i + 1) < s.length()\n                    && (s.charAt(i) != ' ' && s.charAt(i + 1) != '\\t')) {\n                throw new ParseException(\"Illegal character after '?': \"\n                        + s.charAt(i), i);\n            }\n            if (type != DAY_OF_WEEK && type != DAY_OF_MONTH) {","sourceCodeStart":583,"sourceCodeEnd":619,"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#L583-L619","documentation":"The final else in storeExpressionVals: an uppercase alphabetic character (A-Z) reached the branch that is neither MONTH nor DAY_OF_WEEK, so there is no valid name lookup for it. Since name tokens (JAN, MON, etc.) are only meaningful in month/weekday fields, an alpha char in SECOND/MINUTE/HOUR/DAY_OF_MONTH triggers 'Illegal characters for this position'.","triggerScenarios":"Alpha letters placed in a numeric-only field: '0 0 ABC * * ?' (HOUR='ABC'), 'S * * * * ?' (SECOND), 'A B C D E F' garbage, or a stray letter glued to a number like '0 0 1H0 * * ?'. Also a day-of-month token starting with a letter that is not 'L'/'LW' (the L check happens in a later branch but only for the leading char).","commonSituations":"Confusing Linux crond day names with Quartz syntax; pasting a malformed fragment; building the second/minute/hour fields from user free-text that contains letters.","solutions":["Restrict SECOND, MINUTE, HOUR and DAY_OF_MONTH fields to numeric values, '*', '?', '/' and '-' (and 'L'/'W' only where supported).","Remove stray letters; if you intended a named value it belongs in MONTH or DAY_OF_WEEK.","Sanitize user-supplied schedule input by validating field-by-field type before constructing the cron string."],"exampleFix":"// before - alpha in hour field\nString cron = \"0 0 NOON * * ?\";  // 'NOO' -> Illegal characters\n\n// after - numeric hour (12)\nString cron = \"0 0 12 * * ?\";","handlingStrategy":"validation","validationCode":"// Fields SECOND, MINUTE, HOUR and DAY_OF_MONTH must be numeric (with operators), not alpha.\npublic static String validateNumericField(String field, String fieldName) {\n    if (field == null) return fieldName + \" is null\";\n    String t = field.trim().toUpperCase();\n    if (t.matches(\"[0-9*/?\\\\-,LW]+\")) return null; // L/W only valid in dom, but let parser refine\n    if (t.matches(\".*[A-Z].*\")) return fieldName + \" contains illegal alphabetic characters: \" + field;\n    return null;\n}","typeGuard":"public static boolean isAlphaFreeNumericField(String field) {\n    return field != null && !field.toUpperCase().matches(\".*[A-Z].*\");\n}","tryCatchPattern":"try {\n    new CronExpression(expr);\n} catch (ParseException e) {\n    if (e.getMessage().startsWith(\"Illegal characters for this position\")) {\n        return \"Only numeric values (and * ? / -) are allowed in second/minute/hour/day-of-month. \" + e.getMessage();\n    }\n    throw e;\n}","preventionTips":["Reject letters in second/minute/hour/day-of-month fields at the input boundary.","Restrict those fields to the charset [0-9*?/-] (plus L/W for dom only).","Use a cron field builder that types each field (numeric vs name) instead of free text."],"tags":["cron","xxl-job","field-validation","validation","parse-error"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}