Announcement Announcement Module
Collapse
No announcement yet.
FlatFileParseException returning as a 'Non-skippable exception' Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • FlatFileParseException returning as a 'Non-skippable exception'

    Hi,
    I am trying to access the records in a text file and storing them in an other text file. I included the exception 'FlatFileParseException' in <batch:skippable-exception-classes> tag so that any bad record should be skipped. However, when I am accessing the output file, only records which occur before exception-causing record are processed and the records which occur after the exception-causing record are not getting processed. Also the error stack trace shows exception as non-skippable.

    Below are the excerpts from my code-

    input file:
    1,a,b
    2,c,d
    3,e,f
    problem,g,h
    5,i,j
    6,k,l

    bold one is the bad record which should be skipped ideally.

    output file:
    1-ab
    2-cd

    code:
    Code:
    <batch:job id="FileToFileJob">
      <batch:step id="step1">
        <batch:tasklet transaction-manager="transactionManager">
          <batch:chunk reader="FileReader" processor="FileProcessor" writer="FileWriter" commit-interval="2" skip-limit="10">
            <batch:skippable-exception-classes>
              <batch:include class="org.springframework.batch.item.file.FlatFileParseException"/>
            </batch:skippable-exception-classes>
          </batch:chunk>
        </batch:tasklet>
      </batch:step>
    </batch:job>
    error stacktrace:
    Code:
    17:30:37,208 ERROR main FlatFileItemReader:182 - Parsing error at line: 4 in resource=URL [file:C:/ankitFilesRead/text.txt], input=[,g,h]
    org.springframework.batch.item.file.FlatFileParseException: Parsing error at line: 4, input=[problem,g,h].................
    Caused by: java.lang.NumberFormatException: Unparseable number:problem .....................
    17:30:37,223 ERROR main AbstractStep:213 - Encountered an error executing the step: class org.springframework.batch.core.step.skip.NonSkippableReadException: Non-skippable exception during read...............
    Mapper:
    Code:
    public Employee mapFieldSet(FieldSet fs)
    	{
    		if(fs == null)
    		{
    			return null;
    		}
    		
    		Employee emp = new Employee();
    		emp.setId(fs.readInt("id"));
    		emp.setFirstName(fs.readString("firstName"));
    		emp.setLastName(fs.readString("lastName"));
    		
    		return emp;
    	}
    Can you please help me understand why the records below the row- problem,g,h are not getting printed in output file and why the exception is being thrown as non-skippable?
    Last edited by ankitiitgs; Apr 23rd, 2012, 08:24 AM.

  • #2
    Have you got the solution

    Hi ankit,

    am also facing the same problem while trying to skip the data while reading please if u got the solution please let me know .am working on POC of spring batch .could u please help me

    Originally posted by ankitiitgs View Post
    Hi,
    I am trying to access the records in a text file and storing them in an other text file. I included the exception 'FlatFileParseException' in <batch:skippable-exception-classes> tag so that any bad record should be skipped. However, when I am accessing the output file, only records which occur before exception-causing record are processed and the records which occur after the exception-causing record are not getting processed. Also the error stack trace shows exception as non-skippable.

    Below are the excerpts from my code-

    input file:
    1,a,b
    2,c,d
    3,e,f
    problem,g,h
    5,i,j
    6,k,l

    bold one is the bad record which should be skipped ideally.

    output file:
    1-ab
    2-cd

    code:
    Code:
    <batch:job id="FileToFileJob">
      <batch:step id="step1">
        <batch:tasklet transaction-manager="transactionManager">
          <batch:chunk reader="FileReader" processor="FileProcessor" writer="FileWriter" commit-interval="2" skip-limit="10">
            <batch:skippable-exception-classes>
              <batch:include class="org.springframework.batch.item.file.FlatFileParseException"/>
            </batch:skippable-exception-classes>
          </batch:chunk>
        </batch:tasklet>
      </batch:step>
    </batch:job>
    error stacktrace:
    Code:
    17:30:37,208 ERROR main FlatFileItemReader:182 - Parsing error at line: 4 in resource=URL [file:C:/ankitFilesRead/text.txt], input=[,g,h]
    org.springframework.batch.item.file.FlatFileParseException: Parsing error at line: 4, input=[problem,g,h].................
    Caused by: java.lang.NumberFormatException: Unparseable number:problem .....................
    17:30:37,223 ERROR main AbstractStep:213 - Encountered an error executing the step: class org.springframework.batch.core.step.skip.NonSkippableReadException: Non-skippable exception during read...............
    Mapper:
    Code:
    public Employee mapFieldSet(FieldSet fs)
    	{
    		if(fs == null)
    		{
    			return null;
    		}
    		
    		Employee emp = new Employee();
    		emp.setId(fs.readInt("id"));
    		emp.setFirstName(fs.readString("firstName"));
    		emp.setLastName(fs.readString("lastName"));
    		
    		return emp;
    	}
    Can you please help me understand why the records below the row- problem,g,h are not getting printed in output file and why the exception is being thrown as non-skippable?

    Comment

    Working...
    X