{"record":{"id":"b973cb84d6b8fc86","repo":"alibaba/spring-cloud-alibaba","slug":"can-only-be-specfied-for-day-of-month-or-day-o","errorCode":null,"errorMessage":"'?' can only be specfied for Day-of-Month or Day-of-Week.","messagePattern":"'\\?' can only be specfied for Day-of-Month or Day-of-Week\\.","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":392,"sourceCode":"\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) {\n\t\t\t\tthrow new ParseException(\n\t\t\t\t\t\t\"'?' can only be specfied for Day-of-Month or Day-of-Week.\",\n\t\t\t\t\t\ti);\n\t\t\t}\n\t\t\tif (type == DAY_OF_WEEK && !lastdayOfMonth) {\n\t\t\t\tfinal int val = daysOfMonth.last();\n\t\t\t\tif (val == NO_SPEC_INT) {\n\t\t\t\t\tthrow new ParseException(\n\t\t\t\t\t\t\t\"'?' can only be specfied for Day-of-Month -OR- Day-of-Week.\",\n\t\t\t\t\t\t\ti);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\taddToSet(NO_SPEC_INT, -1, 0, type);\n\t\t\treturn i;\n\t\t}\n\n\t\tif (c == '*' || c == '/') {\n\t\t\tif (c == '*' && (i + 1) >= s.length()) {","sourceCodeStart":374,"sourceCodeEnd":410,"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#L374-L410","documentation":"Thrown while parsing a '?' token when the current field type is neither DAY_OF_MONTH nor DAY_OF_WEEK. The '?' modifier is only meaningful for the two day fields (it resolves the Quartz DOM-vs-DOW ambiguity); using it in seconds, minutes, hours, month, or year is illegal. ParseException message: \"'?' can only be specified for Day-of-Month or Day-of-Week.\"","triggerScenarios":"A '?' in a non-day field, e.g. '0 ? 0 * * *' ('?' in minute) or '0 0 0 * ? *' ('?' in month). The check at CronExpression.java:391-394 fires when type != DAY_OF_WEEK && type != DAY_OF_MONTH.","commonSituations":"Assuming '?' is a general wildcard like '*'; converting from a system that uses '?' differently; misplacing the '?' field by one position.","solutions":["Replace '?' in seconds/minutes/hours/month/year with '*' (meaning 'every value').","Keep '?' only in the day-of-month or day-of-week field, and use it for exactly one of the two.","Validate at config load."],"exampleFix":"# before ('?' used in minute position)\n0 ? 0 * * *\n\n# after\n0 * 0 * * ?","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":"// '?' only valid at field index 3 (DOM) and 5 (DOW)\nstatic boolean qOnlyInDayFields(String[] f) {\n    for (int i = 0; i < f.length; i++) {\n        if (\"?\".equals(f[i]) && i != 3 && i != 5) return false;\n    }\n    return true;\n}","tryCatchPattern":"try {\n    new CronExpression(cron);\n} catch (ParseException e) {\n    // \"'?' can only be specified for Day-of-Month or Day-of-Week.\"\n    log.error(\"Misplaced '?' in cron '{}'\", cron);\n}","preventionTips":["Use '*' for 'every value' in non-day fields; reserve '?' exclusively for day-of-month/day-of-week.","Trial-parse crons at config validation."],"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"}