Closed
Description
Bug description
When creating an instance of MongoItemReader
using MongoItemReaderBuilder
and no sorting is set, using the ItemReader results in NPE
Environment
Using dependency spring-boot-starter-batch
, version 2.4.5
Steps to reproduce
@Bean
public ItemReader<Item> publicationReader(MongoOperations mongoOperations,
@Value("#{jobParameters['publicationId']}") String itemId) {
return new MongoItemReaderBuilder<Item>()
.name("currentItem")
.template(mongoOperations)
.collection("items")
.targetType(Item.class)
.pageSize(10)
.query(query(where("_id").is(itemId)))
//.sorts(new HashMap<>()) without this line it throws a NPE in MongoItemReader#convertToSort(Map<String, Sort.Direction> sorts); line 257
.build();
}
Expected behavior
When no sorting is provided, either default sorting should be used, or it should be validated, that sorting is set in MongoItemReaderBuilder#build()
method. There is a validation when using queryString, but no one when using a Query
object
Minimal Complete Reproducible example
See Steps to reproduce