8138721: ElementTraversal: javadoc warning; also, hasFeature shall return true
authorjoehw
Tue, 06 Oct 2015 10:59:52 -0700
changeset 32901 42af6bc4d36a
parent 32900 2a9ad2693d23
child 32902 0bd67eff34ef
8138721: ElementTraversal: javadoc warning; also, hasFeature shall return true Reviewed-by: lancea, dfuchs
jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/CoreDOMImplementationImpl.java
jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/DOMImplementationImpl.java
jaxp/src/java.xml/share/classes/org/w3c/dom/ElementTraversal.java
jaxp/test/javax/xml/jaxp/unittest/dom/ElementTraversal.java
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/CoreDOMImplementationImpl.java	Mon Oct 05 20:25:02 2015 -0700
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/CoreDOMImplementationImpl.java	Tue Oct 06 10:59:52 2015 -0700
@@ -101,7 +101,7 @@
          * This is interpreted as "Version of the DOM API supported for the
          * specified Feature", and in Level 1 should be "1.0"
          *
-         * @return true iff this implementation is compatable with the specified
+         * @return true if this implementation is compatible with the specified
          * feature and version.
          */
         public boolean hasFeature(String feature, String version) {
@@ -111,19 +111,22 @@
             if (feature.startsWith("+")) {
                 feature = feature.substring(1);
             }
-            return (
-                feature.equalsIgnoreCase("Core")
-                    && (anyVersion
-                        || version.equals("1.0")
-                        || version.equals("2.0")
-                        || version.equals("3.0")))
-                        || (feature.equalsIgnoreCase("XML")
-                    && (anyVersion
-                        || version.equals("1.0")
-                        || version.equals("2.0")
-                        || version.equals("3.0")))
-                        || (feature.equalsIgnoreCase("LS")
-                    && (anyVersion || version.equals("3.0")));
+            return (feature.equalsIgnoreCase("Core")
+                        && (anyVersion
+                            || version.equals("1.0")
+                            || version.equals("2.0")
+                            || version.equals("3.0")))
+                    || (feature.equalsIgnoreCase("XML")
+                        && (anyVersion
+                            || version.equals("1.0")
+                            || version.equals("2.0")
+                            || version.equals("3.0")))
+                    || (feature.equalsIgnoreCase("LS")
+                        && (anyVersion
+                            || version.equals("3.0")))
+                    || (feature.equalsIgnoreCase("ElementTraversal")
+                        && (anyVersion
+                            || version.equals("1.0")));
         } // hasFeature(String,String):boolean
 
 
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/DOMImplementationImpl.java	Mon Oct 05 20:25:02 2015 -0700
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/DOMImplementationImpl.java	Tue Oct 06 10:59:52 2015 -0700
@@ -83,6 +83,9 @@
      * specified feature and version.
      */
     public boolean hasFeature(String feature, String version) {
+        if (feature == null || feature.length() == 0) {
+            return false;
+        }
 
         boolean result = super.hasFeature(feature, version);
         if (!result) {
--- a/jaxp/src/java.xml/share/classes/org/w3c/dom/ElementTraversal.java	Mon Oct 05 20:25:02 2015 -0700
+++ b/jaxp/src/java.xml/share/classes/org/w3c/dom/ElementTraversal.java	Tue Oct 06 10:59:52 2015 -0700
@@ -50,7 +50,7 @@
  * elements of an element, for preprocessing before navigation.
  *
  * @see
- * <a href='http://www.w3.org/TR/ElementTraversal/'><cite>Element Traversal Specification</cite></a>.
+ * <a href='http://www.w3.org/TR/ElementTraversal/'><cite>Element Traversal Specification</cite></a>
  *
  * @since 9
  */
--- a/jaxp/test/javax/xml/jaxp/unittest/dom/ElementTraversal.java	Mon Oct 05 20:25:02 2015 -0700
+++ b/jaxp/test/javax/xml/jaxp/unittest/dom/ElementTraversal.java	Tue Oct 06 10:59:52 2015 -0700
@@ -31,16 +31,35 @@
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 import org.w3c.dom.Document;
+import org.w3c.dom.DOMImplementation;
 import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
 
 /*
- * @bug 8135283
+ * @bug 8135283 8138721
  * @summary Tests for the Element Traversal interface.
  */
 
 public class ElementTraversal {
     /*
+       Verifies that ElementTraversal is supported.
+     */
+    @Test(dataProvider = "doc")
+    public void testHasFeature(Document doc) {
+        DOMImplementation di = doc.getImplementation();
+
+        //return false if feasure == null
+        Assert.assertFalse(di.hasFeature(null, null));
+
+        //A feature is supported without specifying version
+        Assert.assertTrue(di.hasFeature("ElementTraversal", null));
+        Assert.assertTrue(di.hasFeature("ElementTraversal", ""));
+
+        //ElementTraversal Version 1.0 is supported
+        Assert.assertTrue(di.hasFeature("ElementTraversal", "1.0"));
+    }
+
+    /*
        Verifies the ElementTraversal interface by exercising all of its five
        methods while reading through the xml document.
      */