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 "Andrzej Roman Cichocki (JIRA)" <xe...@xml.apache.org> on 2005/10/27 18:01:55 UTC

[jira] Created: (XERCESJ-1109) Non-DocumentImpl DOM implementation causes ClassCastExceptions.

Non-DocumentImpl DOM implementation causes ClassCastExceptions.
---------------------------------------------------------------

         Key: XERCESJ-1109
         URL: http://issues.apache.org/jira/browse/XERCESJ-1109
     Project: Xerces2-J
        Type: Bug
  Components: DOM (Level 3 Core)  
    Versions: 2.7.1    
 Environment: jdk1.5.0_04 on Linux
    Reporter: Andrzej Roman Cichocki


The documentation at http://xml.apache.org/xerces2-j/properties.html suggests that setting the value of the http://apache.org/xml/properties/dom/document-class-name property to any implementation of org.w3c.dom.Document should work.

In the following test DocumentWrapper wraps org.apache.xerces.dom.DocumentImpl. All methods simply delegate to DocumentImpl except for createElementNS and createAttributeNS. These wrap the objects returned by the underlying DocumentImpl in ElementWrapper and AttrWrapper respectively. All methods in ElementWrapper and AttrWrapper simply delegate to the underlying Impl.

The aim is for Xerces to build a DOM tree consisting of wrapper instances which should behave in exactly the same way as the underlying Impls. In practice the parser bombs with ClassCastExceptions:

java.lang.ClassCastException: ElementWrapper
	at org.apache.xerces.dom.ParentNode.internalInsertBefore(ParentNode.java:381)
	at org.apache.xerces.dom.ParentNode.insertBefore(ParentNode.java:282)
	at org.apache.xerces.dom.CoreDocumentImpl.insertBefore(CoreDocumentImpl.java:389)
	at org.apache.xerces.dom.NodeImpl.appendChild(NodeImpl.java:235)
	at NodeWrapper.appendChild(NodeWrapper.java:80)
	at org.apache.xerces.parsers.AbstractDOMParser.startElement(AbstractDOMParser.java:1014)
	at org.apache.xerces.parsers.AbstractDOMParser.emptyElement(AbstractDOMParser.java:1099)
	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:277)
	at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(XMLNSDocumentScannerImpl.java:738)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1754)
	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.DOMParser.parse(DOMParser.java:225)
	at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
	at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:98)
	at Main.main(Main.java:16)
java.lang.ClassCastException: AttrWrapper
	at org.apache.xerces.dom.AttributeMap.setNamedItem(AttributeMap.java:89)
	at org.apache.xerces.dom.ElementImpl.setAttributeNode(ElementImpl.java:549)
	at ElementWrapper.setAttributeNode(ElementWrapper.java:37)
	at org.apache.xerces.parsers.AbstractDOMParser.startElement(AbstractDOMParser.java:922)
	at org.apache.xerces.parsers.AbstractDOMParser.emptyElement(AbstractDOMParser.java:1099)
	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:277)
	at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(XMLNSDocumentScannerImpl.java:738)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1754)
	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.DOMParser.parse(DOMParser.java:225)
	at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
	at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:98)
	at Main.main(Main.java:23)

The source code and class files to reproduce these exceptions are in the attached jar. It is runnable as follows provided xercesImpl.jar is in the same directory:

	java -jar xerces-bug.jar



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org


[jira] Updated: (XERCESJ-1109) Non-DocumentImpl DOM implementation causes ClassCastExceptions.

Posted by "Andrzej Roman Cichocki (JIRA)" <xe...@xml.apache.org>.
     [ http://issues.apache.org/jira/browse/XERCESJ-1109?page=all ]

Andrzej Roman Cichocki updated XERCESJ-1109:
--------------------------------------------

    Attachment: xerces-bug.jar

Runnable as follows provided xercesImpl.jar is in the same directory:

java -jar xerces-bug.jar

It also contains the source code.

> Non-DocumentImpl DOM implementation causes ClassCastExceptions.
> ---------------------------------------------------------------
>
>          Key: XERCESJ-1109
>          URL: http://issues.apache.org/jira/browse/XERCESJ-1109
>      Project: Xerces2-J
>         Type: Bug
>   Components: DOM (Level 3 Core)
>     Versions: 2.7.1
>  Environment: jdk1.5.0_04 on Linux
>     Reporter: Andrzej Roman Cichocki
>  Attachments: xerces-bug.jar
>
> The documentation at http://xml.apache.org/xerces2-j/properties.html suggests that setting the value of the http://apache.org/xml/properties/dom/document-class-name property to any implementation of org.w3c.dom.Document should work.
> In the following test DocumentWrapper wraps org.apache.xerces.dom.DocumentImpl. All methods simply delegate to DocumentImpl except for createElementNS and createAttributeNS. These wrap the objects returned by the underlying DocumentImpl in ElementWrapper and AttrWrapper respectively. All methods in ElementWrapper and AttrWrapper simply delegate to the underlying Impl.
> The aim is for Xerces to build a DOM tree consisting of wrapper instances which should behave in exactly the same way as the underlying Impls. In practice the parser bombs with ClassCastExceptions:
> java.lang.ClassCastException: ElementWrapper
> 	at org.apache.xerces.dom.ParentNode.internalInsertBefore(ParentNode.java:381)
> 	at org.apache.xerces.dom.ParentNode.insertBefore(ParentNode.java:282)
> 	at org.apache.xerces.dom.CoreDocumentImpl.insertBefore(CoreDocumentImpl.java:389)
> 	at org.apache.xerces.dom.NodeImpl.appendChild(NodeImpl.java:235)
> 	at NodeWrapper.appendChild(NodeWrapper.java:80)
> 	at org.apache.xerces.parsers.AbstractDOMParser.startElement(AbstractDOMParser.java:1014)
> 	at org.apache.xerces.parsers.AbstractDOMParser.emptyElement(AbstractDOMParser.java:1099)
> 	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:277)
> 	at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(XMLNSDocumentScannerImpl.java:738)
> 	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1754)
> 	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.DOMParser.parse(DOMParser.java:225)
> 	at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
> 	at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:98)
> 	at Main.main(Main.java:16)
> java.lang.ClassCastException: AttrWrapper
> 	at org.apache.xerces.dom.AttributeMap.setNamedItem(AttributeMap.java:89)
> 	at org.apache.xerces.dom.ElementImpl.setAttributeNode(ElementImpl.java:549)
> 	at ElementWrapper.setAttributeNode(ElementWrapper.java:37)
> 	at org.apache.xerces.parsers.AbstractDOMParser.startElement(AbstractDOMParser.java:922)
> 	at org.apache.xerces.parsers.AbstractDOMParser.emptyElement(AbstractDOMParser.java:1099)
> 	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:277)
> 	at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(XMLNSDocumentScannerImpl.java:738)
> 	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1754)
> 	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.DOMParser.parse(DOMParser.java:225)
> 	at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
> 	at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:98)
> 	at Main.main(Main.java:23)
> The source code and class files to reproduce these exceptions are in the attached jar. It is runnable as follows provided xercesImpl.jar is in the same directory:
> 	java -jar xerces-bug.jar

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org


Re: [jira] Resolved: (XERCESJ-1109) Non-DocumentImpl DOM implementation causes ClassCastExceptions.

Posted by Joseph Kesselman <ke...@us.ibm.com>.
One workaround is to use the "user data" hook and/or DOM events to bind
additional information and behavior to the existing DOM implementation,
rather than subclassing.

______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"The world changed profoundly and unpredictably the day Tim Berners Lee
got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk


---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org


[jira] Resolved: (XERCESJ-1109) Non-DocumentImpl DOM implementation causes ClassCastExceptions.

Posted by "Michael Glavassevich (JIRA)" <xe...@xml.apache.org>.
     [ http://issues.apache.org/jira/browse/XERCESJ-1109?page=all ]
     
Michael Glavassevich resolved XERCESJ-1109:
-------------------------------------------

    Resolution: Invalid

You cannot extend a DOM implementation simply by creating wrapper classes around an existing one.  The classes you've created have no inheritence relationship with the Xerces DOM.  You get a ClassCastException because your wrappers are masquerading as nodes created by DocumentImpl.  ElementWrapper and AttrWrapper are not created by DocumentImpl, yet they return DocumentImpl as their owner document.

> Non-DocumentImpl DOM implementation causes ClassCastExceptions.
> ---------------------------------------------------------------
>
>          Key: XERCESJ-1109
>          URL: http://issues.apache.org/jira/browse/XERCESJ-1109
>      Project: Xerces2-J
>         Type: Bug
>   Components: DOM (Level 3 Core)
>     Versions: 2.7.1
>  Environment: jdk1.5.0_04 on Linux
>     Reporter: Andrzej Roman Cichocki
>  Attachments: xerces-bug.jar
>
> The documentation at http://xml.apache.org/xerces2-j/properties.html suggests that setting the value of the http://apache.org/xml/properties/dom/document-class-name property to any implementation of org.w3c.dom.Document should work.
> In the following test DocumentWrapper wraps org.apache.xerces.dom.DocumentImpl. All methods simply delegate to DocumentImpl except for createElementNS and createAttributeNS. These wrap the objects returned by the underlying DocumentImpl in ElementWrapper and AttrWrapper respectively. All methods in ElementWrapper and AttrWrapper simply delegate to the underlying Impl.
> The aim is for Xerces to build a DOM tree consisting of wrapper instances which should behave in exactly the same way as the underlying Impls. In practice the parser bombs with ClassCastExceptions:
> java.lang.ClassCastException: ElementWrapper
> 	at org.apache.xerces.dom.ParentNode.internalInsertBefore(ParentNode.java:381)
> 	at org.apache.xerces.dom.ParentNode.insertBefore(ParentNode.java:282)
> 	at org.apache.xerces.dom.CoreDocumentImpl.insertBefore(CoreDocumentImpl.java:389)
> 	at org.apache.xerces.dom.NodeImpl.appendChild(NodeImpl.java:235)
> 	at NodeWrapper.appendChild(NodeWrapper.java:80)
> 	at org.apache.xerces.parsers.AbstractDOMParser.startElement(AbstractDOMParser.java:1014)
> 	at org.apache.xerces.parsers.AbstractDOMParser.emptyElement(AbstractDOMParser.java:1099)
> 	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:277)
> 	at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(XMLNSDocumentScannerImpl.java:738)
> 	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1754)
> 	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.DOMParser.parse(DOMParser.java:225)
> 	at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
> 	at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:98)
> 	at Main.main(Main.java:16)
> java.lang.ClassCastException: AttrWrapper
> 	at org.apache.xerces.dom.AttributeMap.setNamedItem(AttributeMap.java:89)
> 	at org.apache.xerces.dom.ElementImpl.setAttributeNode(ElementImpl.java:549)
> 	at ElementWrapper.setAttributeNode(ElementWrapper.java:37)
> 	at org.apache.xerces.parsers.AbstractDOMParser.startElement(AbstractDOMParser.java:922)
> 	at org.apache.xerces.parsers.AbstractDOMParser.emptyElement(AbstractDOMParser.java:1099)
> 	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:277)
> 	at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(XMLNSDocumentScannerImpl.java:738)
> 	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1754)
> 	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.DOMParser.parse(DOMParser.java:225)
> 	at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
> 	at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:98)
> 	at Main.main(Main.java:23)
> The source code and class files to reproduce these exceptions are in the attached jar. It is runnable as follows provided xercesImpl.jar is in the same directory:
> 	java -jar xerces-bug.jar

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org