Skip to content

ItemReadListener not being correctly registered after adding a StepExecutionListener #773

Closed
@spring-projects-issues

Description

@spring-projects-issues

Benne Otten opened BATCH-2841 and commented

I've stumbled upon this bug and it gave me quite a headache.
Consider the following Step configuration

@Bean
public Step step1() {
    return steps.get("step1")
        .<SomeDto, SomeDto>chunk(10)
        .reader(reader())
        .processor(processor())
        .writer(writer())
        .listener(stepExecutionListener())
        .listener(itemReadListener())
        .build();
}

I would expect the last listener to register the ItemListener correctly, using the listener(ItemReadLiistener listener) method in the SimpleStepBuilder class, but the listener(Object listener) method in the AbstractTaskletStepBuilder gets invoked instead.

The reason for this is that the listener(StepExecutionListener listener) method resides in the StepBuilderHelper class, and that method returns an AbstractTaskletStepBuilder, and not a SimpleStepBuilder, what it should really return. In other words, the inheritance of SimpleStepBuilder > AbstractTaskletStepBuilder > StepBuilderHelper is messed up.

To illustrate, consider the following tweaked example...

@Bean
public Step step1() {
    return steps.get("step1")
        .<SomeDto, SomeDto>chunk(10)
        .reader(reader())
        .processor(processor())
        .writer(writer())
        .listener(stepExecutionListener())
        .listener(itemReadListener())
        .listener(itemReadListener())
        .build();
}

Here, the first listener(itemReadListener) gets invoked in the AbstractTaskletStepBuilder class (which does nothing for an ItemReadListener) and the second listener(itemReadListener) gets invoked in the SimpleStepBuilder class (as it should).


No further details from BATCH-2841

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions