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

DOMConfiguration.canSetParameter() throws DOMException

    XMLWordPrintable

Details

    • b30
    • generic
    • generic
    • Verified

    Backports

      Description

        Name: eaR10174 Date: 09/05/2003


          The method DOMConfiguration.canSetParameter() throws DOMException in case of the
        parameter "error-handler" and in case of a unrecognized parameter (see test.java below).
        According to DOMConfiguration javadoc
          
            The following list of parameters defined in the DOM:
             
            ...
            
            "error-handler"
            [required] Contains a DOMErrorHandler object.
            
            ...

            public boolean canSetParameter(String name,
                                       Object value)

            Check if setting a parameter to a specific value is supported.

            Parameters:
                name - The name of the parameter to check.
                value - An object. if null, the returned value is true.
            Returns:
                true if the parameter could be successfully set to the specified value, or false
                if the parameter is not recognized or the requested value is not supported. This
                does not change the current value of the parameter itself.


        the method does not throw DOMException and should return true in case of the parameter
        "error-handler" and false in case of the unrecognized parameter.
          
          The bug appears in jdk1.5.0beta-b18 and affects new JCK1.5 tests:
          
            api/org_w3c/dom/DOMConfiguration/index.html#DOMConfiguration[CanSetParameter001]
            api/org_w3c/dom/DOMConfiguration/index.html#DOMConfiguration[CanSetParameter002]

        ------------------------------------test.java-----------------------------
        import javax.xml.parsers.DocumentBuilderFactory;
        import javax.xml.parsers.DocumentBuilder;
        import org.w3c.dom.DOMImplementation;
        import org.w3c.dom.Document;
        import org.w3c.dom.DOMConfiguration;
        import org.w3c.dom.DOMErrorHandler;
        import org.w3c.dom.DOMError;

        public class test {

            public static void main(String argv[]) {
                new test().run();
            }
            
            public void run() {
                try {
                    DOMImplementation domImpl = DocumentBuilderFactory.newInstance()
                                                .newDocumentBuilder()
                                                .getDOMImplementation();
                    
                    Document doc = domImpl.createDocument("namespaceURI", "ns:root", null);
                    
                    DOMConfiguration config = doc.getConfig();
                    DOMErrorHandler handler = new DOMErrorHandler() {
                            public boolean handleError(DOMError error) {
                                return false;
                            }
                    };
                    
                    try {
                        boolean canSet = config.canSetParameter("error-handler", handler);
                        if (!canSet) {
                            System.out.println("Expected: true; Returned: false.");
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    try {
                        System.out.println();
                        boolean canSet = config.canSetParameter("xml123", new Object());
                        if (canSet) {
                            System.out.println("Expected: false; Returned: true.");
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    return;
                }

            }
        }
        --------------------------------------------------------------------------
        % java -showversion test
        java version "1.5.0-beta"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b18)
        Java HotSpot(TM) Client VM (build 1.5.0-beta-b18, mixed mode)

        org.w3c.dom.DOMException: FEATURE_NOT_FOUND: The parameter error-handler is not
        recognized.
                at
        com.sun.org.apache.xerces.internal.dom.DOMConfigurationImpl.canSetParameter(DOMConfigurati
        onImpl.java:905)
                at test.run(test.java:32)
                at test.main(test.java:12)

        org.w3c.dom.DOMException: FEATURE_NOT_FOUND: The parameter xml123 is not recognized.
                at
        com.sun.org.apache.xerces.internal.dom.DOMConfigurationImpl.canSetParameter(DOMConfigurati
        onImpl.java:905)
                at test.run(test.java:39)
                at test.main(test.java:12)
        --------------------------------------------------------------------------

        ======================================================================

        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: