You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "Edwards, Peter" <Pe...@astrazeneca.com> on 2000/12/06 10:16:18 UTC

NullPointerException because of no SystemId

I have seen this issue raised before under the title "Bug? in
org.apache.xerces.reader.DefaultEntityHandler" but have not seen a
resolution. This has been checked against Xerces versions 1.2.1 and 1.2.2.

I have an XML file that contains an external entity, which is an XML
fragment e.g.
	<?xml version="1.0"?>
	<!DOCTYPE feedback  [
	<!ENTITY fb SYSTEM "http://localhost/feedback.xml">
	]>
	<feedback>
	&fb;
	</feedback>

If I use an InputStream to create a SAX InputSource and do not call
setSystemId() then I get the following error in parsing:
	java.lang.NullPointerException
	        at
org.apache.xerces.framework.XMLParser.parse(XMLParser.java:925)
	        at EntityTest.parseFile(EntityTest.java:34)
	        at EntityTest.main(EntityTest.java:118)
If I set the systemId to an empty string (as opposed to it being null) then
the file parses successfully since the URI of the entity is fully qualified.
Obviously, to use a relative URI I have to set the SystemId correctly.

I think the issue is that the error handling is incorrect and a null system
id should be better trapped. I'm afraid I don't have time to delve into the
code and propose a fix at present so I hope someone can make use of this
information.

Pete Edwards

RE: NullPointerException because of no SystemId

Posted by David Parker <dp...@ebt.com>.
The way I resolved this issue in our local copy was to add a null check to
StringPool.addSymbol(), which was calling String.length() without checking
for a null input. The change I made was just to return -1 if a null is
passed in. I sent this along to the list, asking if returning -1 from that
method was reasonable with respect to the rest of the code, but never got an
answer back. At any rate, it seems to be working fine.

- DAP

> -----Original Message-----
> From: Edwards, Peter [mailto:Peter.Edwards@astrazeneca.com]
> Sent: Wednesday, December 06, 2000 3:16 AM
> To: 'xerces-j-dev@xml.apache.org'
> Subject: NullPointerException because of no SystemId
>
>
> I have seen this issue raised before under the title "Bug? in
> org.apache.xerces.reader.DefaultEntityHandler" but have not seen a
> resolution. This has been checked against Xerces versions 1.2.1 and 1.2.2.
>
> I have an XML file that contains an external entity, which is an XML
> fragment e.g.
> 	<?xml version="1.0"?>
> 	<!DOCTYPE feedback  [
> 	<!ENTITY fb SYSTEM "http://localhost/feedback.xml">
> 	]>
> 	<feedback>
> 	&fb;
> 	</feedback>
>
> If I use an InputStream to create a SAX InputSource and do not call
> setSystemId() then I get the following error in parsing:
> 	java.lang.NullPointerException
> 	        at
> org.apache.xerces.framework.XMLParser.parse(XMLParser.java:925)
> 	        at EntityTest.parseFile(EntityTest.java:34)
> 	        at EntityTest.main(EntityTest.java:118)
> If I set the systemId to an empty string (as opposed to it being
> null) then
> the file parses successfully since the URI of the entity is fully
> qualified.
> Obviously, to use a relative URI I have to set the SystemId correctly.
>
> I think the issue is that the error handling is incorrect and a
> null system
> id should be better trapped. I'm afraid I don't have time to
> delve into the
> code and propose a fix at present so I hope someone can make use of this
> information.
>
> Pete Edwards
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org