You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 nullItemWriter 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).
The reason those methods accept null is due to the late binding aspects to how it works. I disagree SimpleStepBuilder should trigger #afterPropertiesSet(). That's really the responsibility of the container. That being said, we should be able to do better validation in the #build() method to prevent this from happening.
I agree with Michael, calling #afterPropertiesSet() is the responsibility of the container.
The important part of this issue is the ability to end up with a chunk oriented step without the mandatory item writer, so I updated the title accordingly.
Marten Deinum Thank you for your PR, it looks good to me. I added a couple of notes on github. If you can manage to address them, your PR will be ready to merge. Thank you upfront.
Marten Deinum opened BATCH-2624 and commented
Using Java based configuration in a project we accidentally created a chunk based step without a writer.
The
SimpleChunkProcessor
expects both theItemProcessor
andItemWriter
to be set (according to the validation done in theafterPropertiesSet
method.The
createTasklet
method in both theSimpleStepBuilder
as well as theFaultTolerantStepBuilder
accept anull
ItemWriter
as long as there is a processor. I would expect aItemWriter
next to anItemReader
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
andItemWriter
are required where anItemProcessor
is optional. (See theChunkElementParser
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
Backported to: 4.1.0.M1, 4.0.2, 3.0.10
The text was updated successfully, but these errors were encountered: