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

Thrown DOMException has INVALID_CHARACTER_ERR instead of NAMESPACE_ERR

    XMLWordPrintable

Details

    • b30
    • generic
    • generic
    • Verified

    Backports

      Description

        Name: eaR10174 Date: 08/27/2003


          The method DOMImplementation.createDocument() throws DOMException with the error code
        INVALID_CHARACTER_ERR in case when the parameter qualifiedName is null and the parameter
        namespaceURI is not null (see test.java below). According to the method javadoc:
          
          Throws:
            DOMException - INVALID_CHARACTER_ERR: Raised if the specified qualified name contains
            an illegal character according to [XML 1.0].
            NAMESPACE_ERR: Raised if the qualifiedName is malformed, if the qualifiedName has a
            prefix and the namespaceURI is null, or if the qualifiedName is null and the
            namespaceURI is different from null, or if the qualifiedName has a prefix that is
            "xml" and the namespaceURI is different from " http://www.w3.org/XML/1998/namespace"
            [XML Namespaces] , or if the DOM implementation does not support the "XML" feature but
            a non-null namespace URI was provided, since namespaces were defined by XML.

        the method should throw DOMException with the error code NAMESPACE_ERR.

          The bug appears in jdk1.5.0beta-b16 and affects a new JCK1.5 test:

             api/org_w3c/dom/DOMImplementation/index.html#CreateDocument[CreateDocument011]

        ------------------------------------test.java-----------------------------
        import javax.xml.parsers.DocumentBuilderFactory;
        import org.w3c.dom.DOMImplementation;
        import org.w3c.dom.Document;
        import org.w3c.dom.DOMException;

        public class test {

            public static void main(String argv[]) {
                new test().run();
            }
            
            public void run() {
                Document document = null;
                try {
                    document = DocumentBuilderFactory.newInstance()
                               .newDocumentBuilder().newDocument();
                } catch (Exception e) {
                    System.out.println("Can't create an empty document.");
                    return;
                }
            
                DOMImplementation implementation = document.getImplementation();

                try {
                    document = implementation.createDocument("http://xxx.xxx", null, null);
                
                    System.out.println("Method does not throw an exception.");
                } catch (DOMException e) {
                    if (e.code == DOMException.NAMESPACE_ERR) {
                        System.out.println("OK");
                    } else {
                        System.out.println("Unexpected error code of exception: " + e );
                    }
                }
            }
        }
        --------------------------------------------------------------------------
        % java -showversion test
        java version "1.5.0-beta"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b16)
        Java HotSpot(TM) Client VM (build 1.5.0-beta-b16, mixed mode)

        Unexpected error code of exception: org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An
        invalid or illegal XML character is specified.
        --------------------------------------------------------------------------
             
        ======================================================================

        Attachments

          Issue Links

            Activity

              People

                nbajajsunw Neeraj Bajaj (Inactive)
                evgsunw Evg Evg (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: