jbarberan / beanio

Automatically exported from code.google.com/p/beanio
0 stars 0 forks source link

NullPointerException thrown when using BeanReaderErrorHandler #55

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?  If applicable, please provide a
mapping configuration and sample record input to recreate the problem.
1. Run the BeanIOVerifier as listed below.
2. See NullPointerException.
3. Comment out line "in.setErrorHandler(new ReaderErrorHandler());" and run it 
again. NullPointerException disappears.  

It seems the use of ErrorHandler causes the reading to continue with errors, 
eventually hits a NullPointerException.

What is the expected output? What do you see instead?
No NullPointerException should be thrown.

What version of BeanIO are you using? What JDK version?
BeanIO 2.0.3
JDK 1.6.0_31

Please provide any additional information below.
=====Content of BeanIOVerifier.java
package fileBean;

import java.io.File;

import org.beanio.BeanReader;
import org.beanio.BeanReaderErrorHandler;
import org.beanio.BeanReaderException;
import org.beanio.StreamFactory;

/**
 * @date Created on 2013-02-01
 */
public class BeanIOVerifier {
    private static String MAPPING_FILE = BeanIOVerifier.class.getPackage().getName().replace('.', '/') + "/BeanIOTest.xml";
    private static String INPUT_FILE = "BeanIOTest.txt";

    public static void main(String[] args) throws Exception {
        // create a BeanIO StreamFactory
        StreamFactory factory = StreamFactory.newInstance();
        // load the mapping file from the working directory
        factory.load(MAPPING_FILE);

        // create a BeanReader to read from "input.csv"
        File currInputFile = new File(BeanIOVerifier.class.getResource(INPUT_FILE).toURI());
        BeanReader in = factory.createReader("test", currInputFile);
        in.setErrorHandler(new ReaderErrorHandler());

        Object record = null;
        while ((record = in.read()) != null) {
        }

        in.close();

        System.out.println("done");
    }
}

class ReaderErrorHandler implements BeanReaderErrorHandler {

    @Override
    public void handleError(BeanReaderException ex) throws Exception {
        System.out.println("Error detected: " + ex);
    }
}
=====End of Content of BeanIOVerifier.java
======Content of BeanIOTest.txt
11111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111
======End of Content of BeanIOTest.txt
======Content of BeanIOTest.xml
<?xml version="1.0" encoding="UTF-8"?>

<beanio xmlns="http://www.beanio.org/2012/03">

    <stream name="test" format="fixedlength" strict="true">
            <record name="fileHeader" order="1" minOccurs="1" maxOccurs="1" minLength="94" maxLength="94" class="map">
                <field name="recordType" length="1" rid="true" literal="1" />
                <field name="filler1" length="93" />
            </record>

            <record name="fileControl" order="2" minOccurs="1" maxOccurs="1" minLength="94" maxLength="94" class="map">
                <field name="recordType" length="1" rid="true" literal="9" />
                <field name="filler1" length="93" />
            </record>

    </stream>
</beanio>
======End of Content of BeanIOTest.xml

Original issue reported on code.google.com by hongqia...@gmail.com on 1 Feb 2013 at 3:14

GoogleCodeExporter commented 8 years ago
See issue 56 for a snapshot JAR that includes a fix.

Original comment by kevin.s...@gmail.com on 2 Feb 2013 at 4:29

GoogleCodeExporter commented 8 years ago

Original comment by kevin.s...@gmail.com on 6 Mar 2013 at 3:13