Announcement Announcement Module
No announcement yet.
nullExceptionPointer with getCurrentResource of MultiResourceItemReader Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • nullExceptionPointer with getCurrentResource of MultiResourceItemReader


    I'm new using spring batch, and I have an issue with MultiResourceItemReader.

    I have a step configured with such a reader, and a listener on that step (reader, writer and processor listener as well) :

    <batch:flow id="multiRefFlow">
        <batch:step id="importRefData">
                <batch:chunk reader="multiRefReader" writer="defaultWriter" skip-policy="defaultSkipPolicy" commit-interval="1" />
                        <bean id="refProcessListener" class="local.ProcessListener">
                            <property name="reader" ref="multiRefReader" />
    <bean id="RefReader" class="org.springframework.batch.item.file.FlatFileItemReader">
        <property name="lineMapper">
            <bean class="local.LineMapper">
                <property name="tokenizer" ref="refLineTokenizer" />
    <bean id="multiRefReader" class="org.springframework.batch.item.file.MultiResourceItemReader">
        <property name="resources">
            <bean id="RefDataFile" factory-bean="resourceLocator" factory-method="getRefFiles" />
        <property name="delegate" ref="RefReader" />

    In afterRead method of the listener, I do some log :"... in file {} ..", reader_.getCurrentResource().getFilename());

    but have null point with reader_.getCurrentResource(), what ever I have one or many files. Actually when debuging, the reader is well injected, with correct resources. but currentRessource index is out of ResourceArray bound. (say 2 if I have 2 resource)

    What is wrong in what I'm doing?

    Thank you

  • #2
    Problem solved,

    in fact it happens that getCurrentResource is null after Read, when all files have been parsed, case that I wasn't filtering. I actually couldn't see this while debuging because of strange buffer fetching exception before normal output. Sorry for inconvenience