Description
Marten Deinum opened BATCH-2624 and commented
Using Java based configuration in a project we accidentally created a chunk based step without a writer.
stepBuilder.chunk(50).reader(someReader).processor(someProcessor).build();
The SimpleChunkProcessor
expects both the ItemProcessor
and ItemWriter
to be set (according to the validation done in the afterPropertiesSet
method.
@Override
protected Tasklet createTasklet() {
Assert.state(reader != null, "ItemReader must be provided");
Assert.state(processor != null || writer != null, "ItemWriter or ItemProcessor must be provided");
RepeatOperations repeatOperations = createChunkOperations();
SimpleChunkProvider<I> chunkProvider = new SimpleChunkProvider<I>(reader, repeatOperations);
SimpleChunkProcessor<I, O> chunkProcessor = new SimpleChunkProcessor<I, O>(processor, writer);
chunkProvider.setListeners(new ArrayList<StepListener>(itemListeners));
chunkProcessor.setListeners(new ArrayList<StepListener>(itemListeners));
ChunkOrientedTasklet<I> tasklet = new ChunkOrientedTasklet<I>(chunkProvider, chunkProcessor);
tasklet.setBuffering(!readerTransactionalQueue);
return tasklet;
}
The createTasklet
method in both the SimpleStepBuilder
as well as the FaultTolerantStepBuilder
accept a null
ItemWriter
as long as there is a processor. I would expect a ItemWriter
next to an ItemReader
to be mandatory (which is also what is expressed in the Spring Batch Documentation) but the java config isn't enforcing this, leading to unexpected behavior.
In the XML configuration an ItemReader
and ItemWriter
are required where an ItemProcessor
is optional. (See the ChunkElementParser
for that).
The change that lead to this was introduced in BATCH-1520 by @david_syer
(so maybe there is a valid reason for this, but still it is weird that XML and Java config lead to different results).
Affects: 3.0.7
Referenced from: pull request #491