Closed
Description
According to Robert. K, MultiResourceItemReader#getCurrentResource
was never meant to be public and is an accidentally leaked implementation detail. Dr D. Syer never liked that getter.
I agree with both of them, this getter is confusing because in order to use it, one needs to inject the item reader in the item processor or line mapper to get the current resource (which is obviously a bad design as it couples batch artefacts), here are a few examples:
- https://stackoverflow.com/questions/63387024/how-to-get-current-resource-name
- https://stackoverflow.com/questions/43097612/accessing-name-of-flat-file-from-flatfileitemreader-linemapper/43098630#43098630
- https://stackoverflow.com/questions/22993633/get-current-resource-name-using-multiresourceitemreader-spring-batch
The correct way to get the current resource is by using the ResourceAware interface which was typically designed for this use case, here is an excerpt from its Javadoc:
Marker interface indicating that an item should have the Spring Resource in which it was read from, set on it.
The canonical example is within MultiResourceItemReader, which will set the current resource on any items
that implement this interface.