Using Xerces 2.7.1 I get NPE trying to parse an empty document, but only when I've set the "continue-after-fatal-error" feature to 'true'. Is this a know issue?

The exception stack trace I get:

java.lang.NullPointerException
        at 
org.apache.xerces.impl.XMLEntityScanner.skipString(XMLEntityScanner.java:1429)
        at 
org.apache.xerces.impl.XMLDocumentScannerImpl$XMLDeclDispatcher.dispatch(XMLDocumentScannerImpl.java:661)
        at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:323)
        at 
org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:807)
        at 
org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:737)
        at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:107)
        at 
org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
        at 
org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
        at ParseEmptySourceTest.main(ParseEmptySourceTest.java:47)

and the sample code I try with:

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;

public class ParseEmptySourceTest {

    public static void main(String[] args) {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setNamespaceAware(true);
        spf.setValidating(false);

        XMLReader xmlReader;
        try {
            xmlReader = spf.newSAXParser()
                        .getXMLReader();
            xmlReader.setFeature("http://apache.org/xml/features/";
                    + "continue-after-fatal-error", true);
        } catch (Exception ex) {
            ex.printStackTrace();
            return;
        }

        DefaultHandler handler = new DefaultHandler() {
            public void fatalError(SAXParseException exception) {
                // continue
            }
        };
        xmlReader.setContentHandler(handler);
        xmlReader.setErrorHandler(handler);

        InputStream emptyInput =
                new ByteArrayInputStream(new byte[0]);
        InputSource testSource = new InputSource(emptyInput);
        try {
            xmlReader.parse(testSource);
        } catch (Exception ex) {
            ex.printStackTrace();
            return;
        }
    }

}

A workaround would be to verify the input is not empty in advance.

--
Stanimir


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to