Skip to content

Starting a flow with Flow#next makes the first step execute twice #4432

@bio-engineer

Description

@bio-engineer

Bug description
If you create a "Flow" and use the "next" method instead of the "start" method to add the first step, then this step will be executed twice.

The problem is in the line addTransition("COMPLETED", next);. It is she who makes Flow perform the step a second time.

Current version:

	private void doNext(Object input) {
		if (this.currentState == null) {
			doStart(input);
		}
		State next = createState(input);
		addTransition("COMPLETED", next);
		addTransition("*", failedState);
		this.currentState = next;
	}

Fixed version:

	private void doNext(Object input) {
		if (this.currentState == null) {
			doStart(input);
		} else {
			State next = createState(input);
			addTransition("COMPLETED", next);
                        addTransition("*", failedState);
			this.currentState = next;
		}
		
	}

Environment

	<groupId>org.springframework.boot</groupId>
 	<artifactId>spring-boot-starter-batch</artifactId>
 	<version>3.1.2</version>

Steps to reproduce

	FlowBuilder<Flow> flowBuilder = new FlowBuilder<>("someFlowName");
	flowBuilder.next(step);
	return flowBuilder.build();

Expected behavior
Created "Flow" with one step. Step executed once.

Minimal Complete Reproducible example
The step was to transfer data from one table to another identical table. The second run of the step failed only because a unique primary key constraint was created.
image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions