United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7099658 Properties.loadFromXML fails with ClassCastException
JDK-7099658 : Properties.loadFromXML fails with ClassCastException

Details
Type:
Bug
Submit Date:
2011-10-11
Status:
Closed
Updated Date:
2012-03-20
Project Name:
JDK
Resolved Date:
2011-11-11
Component:
core-libs
OS:
generic
Sub-Component:
java.util
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
6u22
Fixed Versions:
6u29-rev (b22)

Related Reports
Backport:
Backport:
Backport:
Backport:
Backport:

Sub Tasks

Description
SHORT SUMMARY:
Classcast exception when using non-default JAXP parser 
INDICATORS:
Exception : 
Exception in thread "main" java.lang.ClassCastException:
oracle.xml.parser.v2.DTD cannot be cast to org.w3c.dom.Element
at java.util.XMLUtils.load(XMLUtils.java:61) 

COUNTER INDICATORS:
TRIGGERS:
Use of non-default JAXP parser (oracle xml parser xmlparserv2.jar) in this 
case while making calls into java.util.XMLUtils.load method
KNOWN WORKAROUND:
Modify the parser used.
PRESENT SINCE:
N/A
HOW TO VERIFY:
Testcase presented in BugDB report. oracle xml parser "xmlparserv2.jar" 
should be present in CLASSPATH before running testcase.
NOTES FOR SE:
Logged on jdk 6u22 with linux x86 platform

Fix is simple and suggested by submitter : 

==
The error is in the line:

Element propertiesElement = (Element)doc.getChildNodes().item(1);

which is making an incorrect assumption about the in-memory structure
of the parsed XML document. Instead, it should access the document
element of the XML DOM tree using the standard DOM API getDocumentElement():

Element propertiesElement = doc.getDocumentElement(); 
----
REGRESSION:
No

                                    

Comments
EVALUATION

simple fix is to use the standard parser API call as suggested.
                                     
2011-10-11



Hardware and Software, Engineered to Work Together