You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by bu...@apache.org on 2001/02/08 15:46:19 UTC
[Bug 549] New - NullPointerException when resolving external entities
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=549
*** shadow/549 Thu Feb 8 06:46:19 2001
--- shadow/549.tmp.10544 Thu Feb 8 06:46:19 2001
***************
*** 0 ****
--- 1,73 ----
+ +============================================================================+
+ | NullPointerException when resolving external entities |
+ +----------------------------------------------------------------------------+
+ | Bug #: 549 Product: Xerces-J |
+ | Status: NEW Version: unspecified |
+ | Resolution: Platform: All |
+ | Severity: Normal OS/Version: All |
+ | Priority: Component: Core |
+ +----------------------------------------------------------------------------+
+ | Assigned To: xerces-dev@xml.apache.org |
+ | Reported By: blais@odi.com |
+ | CC list: Cc: |
+ +----------------------------------------------------------------------------+
+ | URL: |
+ +============================================================================+
+ | DESCRIPTION |
+ There is a bug in the StringPool class that we see when we try to resolve
+ external entities and the top level source is an InputStream instead of a
+ SystemID. In other words, using
+
+ org.apache.xerces.parsers.DOMParser.parse(new InputSource(InputStream))
+
+ Fails while
+
+ org.apache.xerces.parsers.DOMParser(new InputSource(systemID)) works.
+
+ I tracked this down to the StringPool.addSymbol() method. I believe
+ that since the InputSource(InputStream) never sets it's systemId, it
+ is null. So when this is passed into addSymbol() the exception occurs.
+
+ It seems that the null should be a valid value so I fixed this locally
+ by patching the code.
+
+ Originally found in version 1_2_0 but also in 1_2_3 and 1_3_0.
+
+
+ In org/apache/xerces/readersDefaultEntityHandler.java, this addSymbol
+ (fSystemId) on line 226 hits the bug.
+
+ public int addExternalEntityDecl(int name, int publicId, int systemId,
+ boolean isExternal) throws Exception {
+
+ ! int entityHandle = fEntityPool.addEntityDecl(name, -1, publicId,
+ systemId, fStringPool.addSymbol(fSystemId), -1, isExternal);
+
+ return entityHandle;
+
+ }
+
+
+
+ fSystemId is null which is perfectly acceptable. But when addSymbol(...) tries
+ to get the length, a NullPointerException is raised. I believe there are other
+ cases where a null could be passed in to addSymbol(). So I added a check to
+ make sure null is acceptable. NULL_STRING is the index to the null string.
+
+
+ diff -cw ./src/org/apache/xerces/utils/StringPool.java ../xerces-
+ 1_2_3/src/org/apache/xerces/utils/StringPool.java
+ *** ./src/org/apache/xerces/utils/StringPool.java Wed Jan 31 20:11:30 2001
+ --- ../xerces-1_2_3/src/org/apache/xerces/utils/StringPool.java Fri Jan 26
+ 17:38:24 2001
+ ***************
+ *** 345,350 ****
+ --- 345,352 ----
+ }
+ }
+ public int addSymbol(String str) {
+ + if( str == null )
+ + return NULL_STRING;
+ int slen = str.length();
+ int hashcode = StringHasher.hashString(str, slen);
+ int hc = hashcode % HASHTABLE_SIZE;