Skip to content

Clarify ItemWriter contract regarding empty chunks #5319

@fmbenhassine

Description

@fmbenhassine

Discussed in #5298

Originally posted by scordio February 19, 2026
Imagine a step where there is an ItemReader and ItemWriter, without an ItemProcessor:

  • The reader returns null immediately
  • The writer is never invoked

So far, everything looks good.

Now imagine a step where there is an ItemReader, an ItemProcessor, and an ItemWriter:

  • The reader returns only one item, then returns null
  • The processor always returns null --> each item is filtered
  • The writer is invoked with an empty chunk

Is the writer's invocation with an empty chunk really intended?

The same behavior also occurs in a fault-tolerant step when skipping all items rather than filtering them.

The background of this question is whether custom writer implementations should expect potential empty chunks. If yes, it might be good to emphasize this in the ItemWriter contract.

We detected it in Spring Batch 4.3.10 and confirmed that 6.0.0 shows the same behavior.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions