{"record":{"id":"ff624f4567245eb6","repo":"alibaba/spring-cloud-alibaba","slug":"hour-values-must-be-between-0-and-23","errorCode":null,"errorMessage":"Hour values must be between 0 and 23","messagePattern":"Hour values must be between 0 and 23","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":775,"sourceCode":"\n\t\treturn i;\n\t}\n\n\tprotected void addToSet(final int val, final int end, int incr, final int type)\n\t\t\tthrows ParseException {\n\n\t\tfinal TreeSet<Integer> set = getSet(type);\n\n\t\tif (type == SECOND || type == MINUTE) {\n\t\t\tif ((val < 0 || val > 59 || end > 59) && (val != ALL_SPEC_INT)) {\n\t\t\t\tthrow new ParseException(\n\t\t\t\t\t\t\"Minute and Second values must be between 0 and 59\",\n\t\t\t\t\t\t-1);\n\t\t\t}\n\t\t}\n\t\telse if (type == HOUR) {\n\t\t\tif ((val < 0 || val > 23 || end > 23) && (val != ALL_SPEC_INT)) {\n\t\t\t\tthrow new ParseException(\n\t\t\t\t\t\t\"Hour values must be between 0 and 23\", -1);\n\t\t\t}\n\t\t}\n\t\telse if (type == DAY_OF_MONTH) {\n\t\t\tif ((val < 1 || val > 31 || end > 31) && (val != ALL_SPEC_INT)\n\t\t\t\t\t&& (val != NO_SPEC_INT)) {\n\t\t\t\tthrow new ParseException(\n\t\t\t\t\t\t\"Day of month values must be between 1 and 31\", -1);\n\t\t\t}\n\t\t}\n\t\telse if (type == MONTH) {\n\t\t\tif ((val < 1 || val > 12 || end > 12) && (val != ALL_SPEC_INT)) {\n\t\t\t\tthrow new ParseException(\n\t\t\t\t\t\t\"Month values must be between 1 and 12\", -1);\n\t\t\t}\n\t\t}\n\t\telse if (type == DAY_OF_WEEK) {\n\t\t\tif ((val == 0 || val > 7 || end > 7) && (val != ALL_SPEC_INT)","sourceCodeStart":757,"sourceCodeEnd":793,"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#L757-L793","documentation":"Thrown in addToSet when an HOUR value (or range end) is outside 0-23, unless it is the ALL_SPEC wildcard sentinel (guard at CronExpression.java:774-777). Hours run 0-23 (midnight = 0).","triggerScenarios":"`new CronExpression(\"0 0 24 * * ?\")` (hour=24), or `0 0 25 * * ?`, or a range like `0 0 0-24 * * ?`.","commonSituations":"Using 24 for midnight (should be 0), a 1-based/AM-PM conversion mistake, or a field-shift placing a day value into the hours field.","solutions":["Keep hours in 0-23; midnight is 0, e.g. '24' -> '0'.","Convert 12-hour AM/PM input to 24-hour before building the string.","Recount the six fields."],"exampleFix":"// before\nnew CronExpression(\"0 0 24 * * ?\");\n// after\nnew CronExpression(\"0 0 0 * * ?\"); // midnight daily","handlingStrategy":"validation","validationCode":"// Hours(field 2) must be 0..23.\nstatic boolean hoursInRange(String[] fields) {\n    if (fields.length < 3) return false;\n    return inRange(fields[2], 0, 23);\n}\nprivate static boolean inRange(String f, int lo, int hi) {\n    if (f.equals(\"*\") || f.equals(\"?\")) return true;\n    for (String part : f.split(\"[-,/LW#]\")) {\n        if (part.isEmpty()) continue;\n        try { int v = Integer.parseInt(part); if (v < lo || v > hi) return false; }\n        catch (NumberFormatException e) { /* ignore names */ }\n    }\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":["Hours are 0-23; midnight is 0, not 24.","Convert 12-hour/AM-PM input to 24-hour before formatting.","Range-check hour values before building the string."],"tags":["cron","schedulerx","spring-cloud-alibaba","configuration","parsing","validation","range-check"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}