jeecgboot/JeecgBoot · error · ParseException

Day-of-Week values must be between 1 and 7

Error message

Day-of-Week values must be between 1 and 7

What it means

Thrown by CronExpression's token parser when the 'L' (last) modifier is used in the day-of-week field but the preceding numeric value falls outside the valid range of 1–7. In this implementation SUN=1 through SAT=7, so values like 0L or 8L are rejected before the lastDayOfWeek flag is set. The check fires inside the character-by-character field parser after an 'L' is detected at the current position.

Source

Thrown at jeecg-boot/jeecg-server-cloud/jeecg-visual/jeecg-cloud-xxljob/src/main/java/com/xxl/job/admin/business/scheduler/cron/CronExpression.java:756

    }

    protected int checkNext(int pos, String s, int val, int type)
            throws ParseException {

        int end = -1;
        int i = pos;

        if (i >= s.length()) {
            addToSet(val, end, -1, type);
            return i;
        }

        char c = s.charAt(pos);

        if (c == 'L') {
            if (type == DAY_OF_WEEK) {
                if(val < 1 || val > 7)
                    throw new ParseException("Day-of-Week values must be between 1 and 7", -1);
                lastDayOfWeek = true;
            } else {
                throw new ParseException("'L' option is not valid here. (pos=" + i + ")", i);
            }
            TreeSet<Integer> set = getSet(type);
            set.add(val);
            i++;
            return i;
        }

        if (c == 'W') {
            if (type != DAY_OF_MONTH) {
                throw new ParseException("'W' option is not valid here. (pos=" + i + ")", i);
            }
            if(val > 31)
                throw new ParseException("The 'W' option does not make sense with values larger than 31 (max number of days in a month)", i);
            nearestWeekdays.add(val);
            i++;

View on GitHub (pinned to 96fb33f5ec)

Solutions

  1. Change the day-of-week number in the 'L' token to a value between 1 and 7 (1=Sunday … 7=Saturday in this library).
  2. If you meant 'last day of the week' generically, use '7L' (last Saturday) or the specific weekday you intend.
  3. Double-check against Quartz cron documentation: 1=SUN, 2=MON, 3=TUE, 4=WED, 5=THU, 6=FRI, 7=SAT.

Example fix

// before
String cron = "0 0 0 ? * 0L";  // 0 is invalid
// after
String cron = "0 0 0 ? * 1L";  // last Sunday of the month
Defensive patterns

Strategy: validation

Validate before calling

// Validate DOW 'L' value before constructing CronExpression
int dowVal = /* the number before 'L' */;
if (dowVal < 1 || dowVal > 7) {
    throw new IllegalArgumentException("Day-of-Week 'L' value must be 1-7, got: " + dowVal);
}

Type guard

boolean isValidDowLToken(String token) {
    if (!token.endsWith("L")) return true;
    try {
        int val = Integer.parseInt(token.substring(0, token.length() - 1));
        return val >= 1 && val <= 7;
    } catch (NumberFormatException e) {
        return false;
    }
}

Try / catch

try {
    CronExpression cron = new CronExpression(expr);
} catch (ParseException e) {
    if (e.getMessage().contains("Day-of-Week values must be between 1 and 7")) {
        // guide user to fix the 'L' weekday token
    }
    throw e;
}

Prevention

When it happens

Trigger: A cron expression containing a day-of-week token of the form <number>L where <number> is less than 1 or greater than 7 — e.g. the DOW field '0L', '8L', or '-1L'. The parser has already consumed the numeric part into `val` and then sees 'L' as the next character with type==DAY_OF_WEEK.

Common situations: Developer assumes 0-based weekdays (0=Sunday) and writes '0 0 0 ? * 0L'; developer copies a cron from a system that uses 0–6 weekday numbering; off-by-one when translating from ISO 8601 (Monday=1..Sunday=7) to this library's Sunday=1 convention.

Related errors


AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14). Data as JSON: /api/errors/60d4397bb43aad1d. Report an issue: GitHub.