[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xerces-j-dev
Subject:    Re: NPE parsing an empty document using "continue-after-fatal-error"
From:       Michael Glavassevich <mrglavas () ca ! ibm ! com>
Date:       2005-11-08 5:57:43
Message-ID: OF7407EB59.DA2A5737-ON852570B3.00201ABA-852570B3.0020BFDE () ca ! ibm ! com
[Download RAW message or body]

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 <stanio@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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic