Skip to content

Commit 2effdc0

Browse files
scordiofmbenhassine
authored andcommitted
Clarify ItemWriter contract regarding empty chunks
Signed-off-by: Stefano Cordio <stefano.cordio@gmail.com>
1 parent f610390 commit 2effdc0

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

  • spring-batch-docs/modules/ROOT/pages/readers-and-writers
  • spring-batch-infrastructure/src/main/java/org/springframework/batch/infrastructure/item

spring-batch-docs/modules/ROOT/pages/readers-and-writers/item-writer.adoc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ interface accepts a list of items, rather than an item by itself. After writing
2626
list, any flushing that may be necessary can be performed before returning from the write
2727
method. For example, if writing to a Hibernate DAO, multiple calls to write can be made,
2828
one for each item. The writer can then call `flush` on the hibernate session before
29-
returning.
30-
29+
returning. Note that the chunk passed to `write` may be empty if all items in the chunk
30+
were filtered out by an `ItemProcessor` or skipped during fault-tolerant step processing.
31+
Implementations are expected to handle empty chunks gracefully.

spring-batch-infrastructure/src/main/java/org/springframework/batch/infrastructure/item/ItemWriter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ public interface ItemWriter<T> {
4141

4242
/**
4343
* Process the supplied data element. Will not be called with any null items in normal
44-
* operation.
45-
* @param chunk of items to be written. Must not be {@code null}.
44+
* operation but might be called with an empty chunk, for example when all items have
45+
* been filtered by an {@link ItemProcessor} or skipped by the fault-tolerant step
46+
* processing. Implementations are expected to handle empty chunks gracefully.
47+
* @param chunk of items to be written. Never {@code null} but may be empty.
4648
* @throws Exception if there are errors. The framework will catch the exception and
4749
* convert or rethrow it as appropriate.
4850
*/

0 commit comments

Comments
 (0)