I am getting a
ClassCastException every time I call getIdentifiers() on my
Document. The
exception occurs at line 1176 in the DeferredDocumentImpl
class'
synchronizeData() method. The code at that line is:
Element element =
(Element)place;
A few lines above
that line, the variable place is declared and initialized
as:
Node place =
this;
I stuck some code in
to print out the inheritance tree for the variable place
just before the line
where the exception occurs. A printout is included below.
Sure enough, there
is no mention of the org.w3c.dom.Element interface in
the inheritance
tree. So the widening cast from DeferredDocumentImpl to
Node works, but a
narrowing cast from DeferredDocumentImpl to Element
does not work. I am
sure the writer thought this was a narrowing cast from
Node to Element as I
did when I first looked at it. It just doesn't work that
way
though.
I
replaced
Element element =
(Element)place; with
Element
element;
if( place instanceof Document ) element = this.getDocumentElement(); else element = (Element)place; and I no longer get
the exception. I think this should work, but I would prefer
someone with more
Xerces history check it and commit it.
Sorry to be so
longwinded, but this was just not that obvious and I wanted to
describe the issue
and resolution clearly.
Thanks,
Chuck
Simpson
Here is the
inheritance printout:
place is of type:
org.apache.xerces.dom.DeferredDocumentImpl
The superclass of org.apache.xerces.dom.DeferredDocumentImpl is:
org.apache.xerces.dom.DocumentImpl
Class org.apache.xerces.dom.DocumentImpl implements: org.w3c.dom.Document Class org.apache.xerces.dom.DocumentImpl implements:
org.apache.xerces.domx.traversal.DocumentTraversal
Class org.apache.xerces.dom.DocumentImpl implements: org.apache.xerces.domx.events.DocumentEvent The superclass of org.apache.xerces.dom.DocumentImpl is: org.apache.xerces.dom.NodeImpl Class org.apache.xerces.dom.NodeImpl implements: org.w3c.dom.Node Class org.apache.xerces.dom.NodeImpl implements: org.w3c.dom.NodeList Class org.apache.xerces.dom.NodeImpl implements: org.apache.xerces.domx.events.EventTarget Class org.apache.xerces.dom.NodeImpl implements: java.lang.Cloneable Class org.apache.xerces.dom.NodeImpl implements: java.io.Serializable The superclass of org.apache.xerces.dom.NodeImpl is: java.lang.Object Class org.apache.xerces.dom.DeferredDocumentImpl implements: org.apache.xerces.dom.DeferredNode java.lang.ClassCastException at org.apache.xerces.dom.DeferredDocumentImpl.synchronizeData(DeferredDocumentImpl.java, Compiled Code) at org.apache.xerces.dom.DocumentImpl.getIdentifier(DocumentImpl.java:827) at com.adhesive.glyph.TestXml.processChild(TestXml.java, Compiled Code) at com.adhesive.glyph.TestXml.processChild(TestXml.java, Compiled Code) at com.adhesive.glyph.TestXml.processChild(TestXml.java, Compiled Code) at com.adhesive.glyph.TestXml.processChild(TestXml.java, Compiled Code) at com.adhesive.glyph.TestXml.init(TestXml.java, Compiled Code) at com.adhesive.glyph.TestXml.main(TestXml.java:179) |