This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 931 - org.w3c.dom.Document cannot be cast to org.w3c.dom.Element
Summary: org.w3c.dom.Document cannot be cast to org.w3c.dom.Element
Status: NEW
Alias: None
Product: DOM TS
Classification: Unclassified
Component: DOM Level 3 (show other bugs)
Version: unspecified
Hardware: Other Windows 3.1
: P1 normal
Target Milestone: ---
Assignee: Philippe Le Hegaret
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-10-29 16:15 UTC by Yash Talwar
Modified: 2012-12-04 00:52 UTC (History)
0 users

See Also:


Attachments

Description Yash Talwar 2004-10-29 16:15:19 UTC
I have been trying to use the DOM Level 3 Test Suite for XPath API.  I think
there is a bug in the following testcase:

org.w3c.domts.level3.xpath.XPathEvaluator_evaluate_document

This test case has following code:
----------------------------------------
public void runTest() throws Throwable {
   Document doc;
   XPathEvaluator xpEvaluator;
   Element root;
   XPathResult result;
   XPathNSResolver nullNSResolver = null;

   XPathResult nullResult = null;

   doc = (Document) load("staffNS", false);
   xpEvaluator = (XPathEvaluator) createXPathEvaluator(doc);
   root = (Element)  doc; // This line has problem.
   result = (XPathResult) xpEvaluator.evaluate("/", root, nullNSResolver,    
              (short) 0, ((Object) /*XPathResult */nullResult));
   assertNotNull("notnull", result);
}
-----------------------------------

The line of code:

root = (Element) doc;

has a problem.
This line tries to cast org.w3c.dom.Document to org.w3c.dom.Element.  This line
results in ClassCastException because these two interfaces are not in same
inheritance tree.

This line of code should be changed as follows:

root = doc.getDocumentElement();

The identical problem is also seen in other testcases such as follows:

org.w3c.domts.level3.xpath.XPathExpression_evaluate_document
has a line in runTest() method:

contextNode = (Element)  doc;  // throws ClassCastException.

should be changed to:

contextNode = doc.getDocumentElement();