You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Stanimir Stamenkov <st...@myrealbox.com> on 2005/11/03 14:20:52 UTC
NPE parsing an empty document using "continue-after-fatal-error"
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: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: NPE parsing an empty document using "continue-after-fatal-error"
Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Stanimir,
Haven't seen this one before, but it was due to the parser not stopping
after reporting the error for the empty stream. Since there's no input it
should never reach the document scanner. Just checked a fix into SVN.
Thanks.
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
Stanimir Stamenkov <st...@myrealbox.com> wrote on 11/03/2005 08:20:52 AM:
> 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: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org