Announcement Announcement Module
Collapse
No announcement yet.
FlatFileParseException : Caused by: java.lang.IllegalArgumentException: Cannot access Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • FlatFileParseException : Caused by: java.lang.IllegalArgumentException: Cannot access

    Hi,

    When debugging, person's Objnr sets fine. but While setting the Oppdate I am getting error as follows:


    org.springframework.batch.item.file.FlatFileParseE xception: Parsing error at line: 1 in resource=class path resource ..., input=[123456782007112812345678901ShahulHameed

    at org.springframework.batch.item.file.FlatFileItemRe ader.read(FlatFileItemReader.java:186)
    at org.springframework.batch.item.support.DelegatingI temReader.read(DelegatingItemReader.java:60)
    at org.springframework.batch.core.step.item.BatchList enerFactoryHelper$1.read(BatchListenerFactoryHelpe r.java:68)
    at org.springframework.batch.core.step.item.SimpleIte mHandler.doRead(SimpleItemHandler.java:83)
    at org.springframework.batch.core.step.item.SimpleIte mHandler.read(SimpleItemHandler.java:75)
    at org.springframework.batch.core.step.item.SimpleIte mHandler.handle(SimpleItemHandler.java:62)
    at org.springframework.batch.core.step.item.ItemOrien tedStep$2.doInIteration(ItemOrientedStep.java:495)
    at org.springframework.batch.repeat.support.RepeatTem plate.getNextResult(RepeatTemplate.java:346)
    at org.springframework.batch.repeat.support.RepeatTem plate.executeInternal(RepeatTemplate.java:212)
    at org.springframework.batch.repeat.support.RepeatTem plate.iterate(RepeatTemplate.java:143)
    at org.springframework.batch.core.step.item.ItemOrien tedStep.processChunk(ItemOrientedStep.java:488)
    at org.springframework.batch.core.step.item.ItemOrien tedStep$1.doInIteration(ItemOrientedStep.java:288)
    at org.springframework.batch.repeat.support.RepeatTem plate.getNextResult(RepeatTemplate.java:346)
    at org.springframework.batch.repeat.support.RepeatTem plate.executeInternal(RepeatTemplate.java:212)
    at org.springframework.batch.repeat.support.RepeatTem plate.iterate(RepeatTemplate.java:143)
    at org.springframework.batch.core.step.item.ItemOrien tedStep.execute(ItemOrientedStep.java:269)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:310)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:182)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :149)
    at org.springframework.aop.aspectj.AspectJAfterAdvice .invoke(AspectJAfterAdvice.java:42)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
    at org.springframework.aop.aspectj.AspectJAfterAdvice .invoke(AspectJAfterAdvice.java:42)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
    at org.springframework.aop.aspectj.AspectJAfterThrowi ngAdvice.invoke(AspectJAfterThrowingAdvice.java:54 )
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
    at org.springframework.aop.framework.adapter.MethodBe foreAdviceInterceptor.invoke(MethodBeforeAdviceInt erceptor.java:50)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
    at org.springframework.aop.aspectj.AspectJAfterThrowi ngAdvice.invoke(AspectJAfterThrowingAdvice.java:54 )
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
    at org.springframework.aop.framework.adapter.MethodBe foreAdviceInterceptor.invoke(MethodBeforeAdviceInt erceptor.java:50)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
    at org.springframework.aop.interceptor.ExposeInvocati onInterceptor.invoke(ExposeInvocationInterceptor.j ava:90)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy2.execute(Unknown Source)
    at org.springframework.batch.core.job.SimpleJob.execu te(SimpleJob.java:125)
    at org.springframework.batch.core.launch.support.Simp leJobLauncher$1.run(SimpleJobLauncher.java:86)
    at org.springframework.core.task.SyncTaskExecutor.exe cute(SyncTaskExecutor.java:49)
    at org.springframework.batch.core.launch.support.Simp leJobLauncher.run(SimpleJobLauncher.java:81)
    at org.springframework.batch.sample.AbstractBatchLaun cherTests.testLaunchJob(AbstractBatchLauncherTests .java:87)
    at org.springframework.batch.sample.AbstractValidatin gBatchLauncherTests.testLaunchJob(AbstractValidati ngBatchLauncherTests.java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at junit.framework.TestCase.runTest(TestCase.java:154 )
    at junit.framework.TestCase.runBare(TestCase.java:127 )
    at org.springframework.test.ConditionalTestCase.runBa re(ConditionalTestCase.java:76)
    at junit.framework.TestResult$1.protect(TestResult.ja va:106)
    at junit.framework.TestResult.runProtected(TestResult .java:124)
    at junit.framework.TestResult.run(TestResult.java:109 )
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:2 08)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at org.junit.internal.runners.JUnit38ClassRunner.run( JUnit38ClassRunner.java:81)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:38)
    at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:196)
    Caused by: java.lang.IllegalArgumentException: Cannot access column [OPPDATE] from [OBJNR, OPPDATE]
    at org.springframework.batch.item.file.mapping.Defaul tFieldSet.indexOf(DefaultFieldSet.java:441)
    at org.springframework.batch.item.file.mapping.Defaul tFieldSet.readInt(DefaultFieldSet.java:218)
    at org.springframework.batch.sample.mapping.PersonFie ldSetMapper.mapLine(PersonFieldSetMapper.java:18)
    at org.springframework.batch.item.file.FlatFileItemRe ader.read(FlatFileItemReader.java:182)
    ... 64 more
    21:39:58,332 INFO Thread-2 SessionFactoryImpl:769 - closing
    My Xml Bean :

    Code:
    <bean id="personFileItemReader"
    		class="org.springframework.batch.item.file.FlatFileItemReader">
    		<property name="resource"
    			value="classpath:data/person/inputfile/${person.file.name}" />
    		<property name="lineTokenizer">
    			<bean
    				class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
    			 <property name="names"
    					value="OBJNR, OPPDATE" />
    				<property name="columns" value="1-8, 9-16" /> 
    			</bean>
    		</property>
    		<property name="fieldSetMapper">
    			<bean
    				class="org.springframework.batch.sample.mapping.PersonFieldSetMapper" />
    		</property>
    		<property name="saveState" value="true" />
    	</bean>
    Data : Person_Sample.txt
    123456782007112812345678901

    Code:
    public class PersonFieldSetMapper implements FieldSetMapper {
    	public Object mapLine(FieldSet fs) {
    		
    		if(fs == null){
    			return null;
    		}
    		
    		Person person = new Person();
    		person.setObjnr(fs.readInt("OBJNR"));
    		person.setOppDate(fs.readInt("OPPDATE"));
    
                    return person;
              }
    
    }
    Pls help.

    Thanks,
    Vaswin

  • #2
    Can you maybe try without the whitespace in the field descriptor, ie "1-8,9-16"? Sorry, I can't try it myself at the minute.

    Comment


    • #3
      I tried this example without spaces as mentioned above. But the same exception is generated..

      Comment


      • #4
        That's very weird. The exception is being thrown because the column name 'OPPDATE' isn't found:

        Code:
        Caused by: java.lang.IllegalArgumentException: Cannot access column [OPPDATE] from [OBJNR, OPPDATE]
        at org.springframework.batch.item.file.mapping.Defaul tFieldSet.indexOf(DefaultFieldSet.java:441)
        Which is thrown from the following block of code:

        Code:
        	protected int indexOf(String name) {
        		if (names == null) {
        			throw new IllegalArgumentException("Cannot access columns by name without meta data");
        		}
        		int index = names.indexOf(name);
        		if (index >= 0) {
        			return index;
        		}
        		throw new IllegalArgumentException("Cannot access column [" + name + "] from " + names);
        	}
        I can't figure out why indexOf would return a negative number, since the output of the exception shows that 'OPPDATE' is definitely in the list.

        Comment


        • #5
          Thank You very much..

          Its works fine.

          Vaswin.

          Comment


          • #6
            I tried without spaces in both at "names" and "columns" as below, it works fine.

            <property name="lineTokenizer">
            <bean
            class="org.springframework.batch.item.file.transfo rm.FixedLengthTokenizer">
            <property name="names" value="OBJNR,OPPDATE" />
            <property name="columns" value="1-8,9-16" />
            </bean>
            </property>

            Comment

            Working...
            X