MultiResourceItemWriter does not validate non-positive itemCountLimitPerResource values
Bug description
MultiResourceItemWriter accepts zero or negative values for itemCountLimitPerResource, although these values cause failures during writing.
With a limit of zero and a non-empty chunk, write() repeatedly delegates empty chunks and advances to the next resource without processing any items. The loop cannot complete normally.
A negative limit instead leads to an invalid sublist range during writing.
Steps to reproduce
- Configure a
MultiResourceItemWriterwith a delegate and an output resource. - Set
itemCountLimitPerResourceto0. - Open the writer.
- Write a non-empty chunk.
The writer repeatedly attempts to write empty chunks and switches resources without making progress.
Setting the limit to -1 instead causes an invalid sublist range during writing.
Expected behavior
Non-positive limits should be rejected with an IllegalArgumentException during configuration, before writing begins.
This should apply to both direct configuration through setItemCountLimitPerResource and construction through MultiResourceItemWriterBuilder.build().
Actual behavior
Both configuration paths accept 0 and negative values without throwing an exception. The invalid configuration is only exposed when writing begins.
Additional context
For a limit of zero and a chunk containing one item, the number of items to write is calculated as:
itemsToWrite = min(remaining resource capacity, remaining chunk items)
= min(0, 1)
= 0
The processed item count remains zero, while the resource limit is already reached (0 >= 0). The writer advances to the next resource and repeats the same calculation.
Parameterized tests expecting IllegalArgumentException for 0 and -1 fail through both configuration paths because no exception is thrown. These tests demonstrate the missing validation; they do not execute the non-terminating write loop.