spring-projects / spring-projects/spring-batch

Conditional Flow for steps does not work

Open
#4,328 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

related-to: flow-definition status: waiting-for-reporter type: bug
Dominant language
Java
Stars
3k
Forks
2.5k
Avg merge
6d 53m
Merged PRs (30d)
3

Description

Condition flow mention in the spring document not working as expected.

Environment
spring-boot-starter-parent - 3.0.1
spring.batch.version - 5.0.0

As mentioned here I have used a similar approach to my job (https://docs.spring.io/spring-batch/docs/current/reference/html/step.html#conditionalFlow)

public Job exportJob() {
    return new JobBuilder(jobname, jobRepository)
        .incrementer(new RunIdIncrementer())
        .listener(jobListener)
        .start(step1("params"))
            .next(step2())
            .on("COMPLETED").to(step3())
            .from(step2()).on("COMPLETED").to(step4())
        .end()
        .build();
  }

I want the step4 to be executed on the failure of step2 and step3 on success.
Currently whichever condition in mention in the 'on' statement that works fine but condition mention in 'from' statement is ignored and I get this error.

org.springframework.batch.core.JobExecutionException: Flow execution ended unexpectedly
	at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:143) ~[spring-batch-core-5.0.0.jar:5.0.0]
	at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:316) ~[spring-batch-core-5.0.0.jar:5.0.0]
	at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:157) ~[spring-batch-core-5.0.0.jar:5.0.0]
	at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) ~[spring-core-6.0.3.jar:6.0.3]
	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:148) ~[spring-batch-core-5.0.0.jar:5.0.0]
	at org.springframework.batch.core.launch.support.TaskExecutorJobLauncher.run(TaskExecutorJobLauncher.java:70) ~[spring-batch-core-5.0.0.jar:5.0.0]
Caused by: org.springframework.batch.core.job.flow.FlowExecutionException: Ended flow=ExportPipeline at state=ExportPipeline.step2 with exception
	at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:177) ~[spring-batch-core-5.0.0.jar:5.0.0]
	at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:142) ~[spring-batch-core-5.0.0.jar:5.0.0]
	at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:137) ~[spring-batch-core-5.0.0.jar:5.0.0]

Is this an issue with spring batch?
Could I please get a solution for such a conditional scenario for the steps execution?
Thanks in advance.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the shown job definition and inspect the flow handling referenced by FlowJob.java and SimpleFlow.java, focusing on the step2 failure path and the from/on transitions. Done means a failure from step2 reaches step4, success reaches step3, and the behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.