Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7099658

Properties.loadFromXML fails with ClassCastException

XMLWordPrintable

    • b22
    • generic
    • generic
    • Verified

        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

              coffeys Sean Coffey
              shadowbug Shadow Bug
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: