{"record":{"id":"6cc68ac6fe1b0065","repo":"alibaba/spring-cloud-alibaba","slug":"can-only-be-specfied-for-day-of-month-or-day","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":399,"sourceCode":"\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()) {\n\t\t\t\taddToSet(ALL_SPEC_INT, -1, incr, type);\n\t\t\t\treturn i + 1;\n\t\t\t}\n\t\t\telse if (c == '/'\n\t\t\t\t\t&& ((i + 1) >= s.length() || s.charAt(i + 1) == ' ' || s\n\t\t\t\t\t.charAt(i + 1) == '\\t')) {\n\t\t\t\tthrow new ParseException(\"'/' must be followed by an integer.\", i);","sourceCodeStart":381,"sourceCodeEnd":417,"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#L381-L417","documentation":"Thrown while parsing the DAY_OF_WEEK '?' token when the DAY_OF_MONTH field was also set to '?' (NO_SPEC). Quartz requires exactly one of the two day fields to be '?' and the other to carry a value; setting '?' for both is illegal. ParseException message: \"'?' can only be specified for Day-of-Month -OR- Day-of-Week.\"","triggerScenarios":"An expression with '?' in both day positions, e.g. '0 0 0 ? * ?'. When processing the DOW '?' the parser reads daysOfMonth.last(); if that value is NO_SPEC_INT (98, meaning DOM was also '?') it throws at CronExpression.java:397-401.","commonSituations":"Using '? * ?' pattern thinking '?' means 'ignore both'; converting from a dialect that allows '?' in both; a template that defaults both day fields to '?'.","solutions":["Set exactly one day field to a real value and the other to '?': e.g. '0 0 0 * * ?' (every day via DOM='*') or '0 0 0 ? * *' (every day via DOW='*').","If you want 'every day', use '*' for day-of-month and '?' for day-of-week.","Validate at config load."],"exampleFix":"# before ('?' in both day fields)\n0 0 0 ? * ?\n\n# after (every day: DOM='*', DOW='?')\n0 0 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":"// exactly one of DOM(3)/DOW(5) must be '?'\nstatic boolean exactlyOneDayFieldIsQ(String[] f) {\n    if (f.length < 6) return false;\n    boolean a = \"?\".equals(f[3]);\n    boolean b = \"?\".equals(f[5]);\n    return a ^ b;\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(\"Use '?' for only ONE day field in cron '{}'\", cron);\n}","preventionTips":["Rule: one day field gets a value, the other gets '?' — never both '?'.","For 'every day', prefer '* * ?' over '? * ?'."],"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"}