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

  • nullExceptionPointer with getCurrentResource of MultiResourceItemReader

    Hello,

    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) :

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

    In afterRead method of the listener, I do some log :

    log.info("... 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

    Comment

    Working...
    X