To whom it may concern (presumably everybody on the list),
 
lazy evaluation mode of DOMParser seems to have a nasty bug.
Here's the story:
 
======== my code =======
.....
DOMParser parser = new DOMParser("file_name");
parser.setErrorHandler(myHandler); // just to see if I'm missing something
parser.parse("file.xml");
Document doc = parser.getDocument();
parser.reset();            // I tried with and without - just bear with me
.....
Element elem = doc.getElementById("myid");
.....
 
========= my file.xml =============
<?xml version="1.0" standalone="yes" ?>
<!DOCTYPE mydoc [
     <!ELEMENT mydoc (myelem1*)>
     <!ELEMENT myelem1 (myelem2*)>
     <!ATTLIST myelem1
          id    ID      #REQUIRED>
     <!ELEMENT myelem2 EMPTY>
     <!ATTLIST account
          id    ID      #REQUIRED
          name   CDATA     #REQUIRED>
]>
<mydoc>
     <myelem1 id="dmitri">
      <myelem2 id="id1" name="name1"/>
      <myelem2 id="id2" name="name2"/>
      <myelem3 id="id3" name="name3"/>
    </myelem1>   
</mydoc>
========= what happens ============
I get an exception with following stack trace:
 
java.lang.NullPointerException
 at java.util.Hashtable.put(Hashtable.java, Compiled Code)
 at org.apache.xerces.dom.DeferredDocumentImpl.putIdentifier0(DeferredDocumentImpl.java:1576)
 at org.apache.xerces.dom.DeferredDocumentImpl.getNodeObject(DeferredDocumentImpl.java, Compiled Code)
 at org.apache.xerces.dom.DeferredElementImpl.synchronizeChildren(DeferredElementImpl.java, Compiled Code)
 at org.apache.xerces.dom.NodeContainer.getFirstChild(NodeContainer.java:273)
 at org.apache.xerces.dom.DeferredDocumentImpl.synchronizeData(DeferredDocumentImpl.java, Compiled Code)
 at org.apache.xerces.dom.DocumentImpl.getIdentifier(DocumentImpl.java:853)
 at org.apache.xerces.dom.DocumentImpl.getElementById(DocumentImpl.java:813)
 at om.poc.OV$Entitler.entitled(OV.java, Compiled Code)
 at om.poc.OV$Entitler.canWrite(OV.java:158)
 at om.poc.OV.main(OV.java, Compiled Code)
 
========= what I do next ============
I comment out this "parser.reset()" - it's suspicious
 
========= what happens after that =========
I get this:
 
java.lang.ClassCastException
 at org.apache.xerces.dom.DeferredDocumentImpl.synchronizeData(DeferredDocumentImpl.java, Compiled Code)
 at org.apache.xerces.dom.DocumentImpl.getIdentifier(DocumentImpl.java:853)
 at org.apache.xerces.dom.DocumentImpl.getElementById(DocumentImpl.java:813)
 at om.poc.OV$Entitler.entitled(OV.java, Compiled Code)
 at om.poc.OV$Entitler.canWrite(OV.java:158)
 at om.poc.OV.main(OV.java, Compiled Code)
 
========= what I do next =========
I put in following line:
    parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
 
======== guessed what happens? ========
It works without any exceptions or parsing errors.
 
======= my environment ==============
It's Win32 (NT 4.0) Xerces 1.0.3 (downloaded March 14),
Sun JDK 1.2.2_001, native threads
Tried it with both javac and the latest jikes compiler - no difference in behaviour, except for compilation speed
 
I peeked into the sources: it looks like (null) String reference is being returned from fStringPool - StringPool does indeed return nulls, without anybody checking for this possibility in DeferredDocumentImpl code.
 
Contact me if you need more details.
 
Regards,

Dmitri Etkine
___________________________________________
            IntegraSolv Corp.
Information and Communications Engineering
___________________________________________
                               1715 Hway 35, suite 201
                               Middletown NJ 07748
e-mail: [EMAIL PROTECTED]        
voice:  (732) 615-0054 ext.30
fax:    (732) 615-9188
 

 

Reply via email to