CronExpression throws IllegalArgumentException when you use following expression:

new CronExpression.parse("* 5,10-30/2 * * * *")
java.lang.IllegalArgumentException: For input string: "5,10" '5,10-30/2' in cron expression "* 5,10-30/2 * * * *"
    at org.springframework.scheduling.support.CronExpression.parse(CronExpression.java:201)
    at org.jetbrains.kotlin.idea.scratch.generated.ScratchFileRunnerGenerated$ScratchFileRunnerGenerated.generated_get_instance_res0(tmp.kt:11)
    at org.jetbrains.kotlin.idea.scratch.generated.ScratchFileRunnerGenerated.main(tmp.kt:20)
Caused by: java.lang.IllegalArgumentException: For input string: "5,10" '5,10-30/2'
    at org.springframework.scheduling.support.BitsCronField.parseField(BitsCronField.java:150)
    at org.springframework.scheduling.support.BitsCronField.parseMinutes(BitsCronField.java:75)
    at org.springframework.scheduling.support.CronField.parseMinutes(CronField.java:66)
    at org.springframework.scheduling.support.CronExpression.parse(CronExpression.java:191)
    ... 2 more
Caused by: java.lang.NumberFormatException: For input string: "5,10"
    at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.base/java.lang.Integer.parseInt(Integer.java:652)
    at java.base/java.lang.Integer.parseInt(Integer.java:770)
    at org.springframework.scheduling.support.BitsCronField.parseRange(BitsCronField.java:165)
    at org.springframework.scheduling.support.BitsCronField.parseField(BitsCronField.java:135)
    ... 5 more

CronSequenceGenerator is able to parse the same expression.

new CronSequenceGenerator("* 5,10-30/2 * * * *")

Affects: 5.3

Comment From: wagnerluis1982

Affects: 5.2.3

How can this affects 5.2.3 given CronExpression was introduced in 5.3? :thinking:

See @since 5.3 in https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/support/CronExpression.html

Comment From: wagnerluis1982

Well, anyway, I just tested using Spring Boot 2.4.1 (in which ships with Spring Framework 5.3.2) and I could reproduce the problem. Given CronSequenceGenerator is deprecated in favor of CronExpression, it should be expected to have the same behavior.

In the following you can get a failing code:

package com.example.demo;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.support.CronExpression;
import org.springframework.scheduling.support.CronSequenceGenerator;

@SpringBootApplication
public class Application implements ApplicationRunner {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        String expression = "* 5,10-30/2 * * * *";
        new CronSequenceGenerator(expression);  // OK
        CronExpression.parse(expression);       // throws IllegalArgumentException
    }
}

Comment From: m15o

Affects: 5.2.3

Typo. Updated issue. Thanks for pointing it out!