flowable/flowable-engine · 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

checkNext enforces that when the 'L' (last) option is used in the DAY_OF_WEEK field, the preceding value must be between 1 and 7. A value outside that range (or 0, which some dialects allow for Sunday) cannot denote a weekday for 'nL', so parsing fails.

Solutions

  1. Replace 0 with 7 (or 'SUN') when targeting Sunday, e.g. "? * 7L" for last Sunday
  2. Use weekday values 1-7 only, or names SUN-SAT
  3. Pre-normalize expressions from Unix cron (0-based weekday) before passing to Flowable

Example fix

// before
new CronExpression("0 0 0 ? * 0L");
// after
new CronExpression("0 0 0 ? * 7L"); // last Sunday
Defensive patterns

Strategy: validation

Validate before calling

int normalizeDayOfWeek(int dow) {
    if (dow == 0) return 7; // Unix-style 0=Sunday -> Quartz 7
    if (dow < 1 || dow > 7) throw new IllegalArgumentException("Day-of-week must be 1-7");
    return dow;
}

Try / catch

try {
    CronExpression cron = new CronExpression(expr);
} catch (ParseException e) {
    if (e.getMessage().equals("Day-of-Week values must be between 1 and 7")) {
        throw new ConfigurationException("Use 1-7 (or SUN-SAT) for day-of-week, not 0: " + expr, e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Expressions like "0 0 0 ? * 0L" or "0 0 0 ? * 8L" where the weekday qualifier before L is not 1-7.

Common situations: Porting cron expressions from systems where 0 = Sunday (e.g. standard Unix cron) into Quartz/Flowable, where Sunday is 7 or SUN.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11). Data as JSON: /api/errors/f410217f11c463be. Report an issue: GitHub.

Appendix: source

Thrown at modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/calendar/CronExpression.java:738

        }
    }

    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) {
                nearestWeekday = true;
            } else {
                throw new ParseException("'W' option is not valid here. (pos=" + i + ")", i);
            }
            if (val > 31) {

View on GitHub (pinned to d6d39ce1c6)