changeset 54613:090395557398

8216408: XMLStreamWriter setDefaultNamespace(null) throws NullPointerException Reviewed-by: dfuchs, lancea
author joehw
date Fri, 25 Jan 2019 14:28:43 -0800
parents 898dd0dc7ac0
children 8c035b34248d
files src/java.xml/share/classes/com/sun/xml/internal/stream/writers/XMLStreamWriterImpl.java test/jaxp/javax/xml/jaxp/unittest/stream/XMLStreamWriterTest/XMLStreamWriterTest.java
diffstat 2 files changed, 24 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.xml/share/classes/com/sun/xml/internal/stream/writers/XMLStreamWriterImpl.java	Fri Jan 25 13:37:12 2019 -0800
+++ b/src/java.xml/share/classes/com/sun/xml/internal/stream/writers/XMLStreamWriterImpl.java	Fri Jan 25 14:28:43 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -44,6 +44,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Random;
 import java.util.Set;
 import javax.xml.XMLConstants;
@@ -1729,12 +1730,7 @@
      */
     private boolean isDefaultNamespace(String uri) {
         String defaultNamespace = fInternalNamespaceContext.getURI(DEFAULT_PREFIX);
-
-        if (uri.equals(defaultNamespace)) {
-            return true;
-        }
-
-        return false;
+        return Objects.equals(uri, defaultNamespace);
     }
 
     /**
--- a/test/jaxp/javax/xml/jaxp/unittest/stream/XMLStreamWriterTest/XMLStreamWriterTest.java	Fri Jan 25 13:37:12 2019 -0800
+++ b/test/jaxp/javax/xml/jaxp/unittest/stream/XMLStreamWriterTest/XMLStreamWriterTest.java	Fri Jan 25 14:28:43 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -42,11 +42,11 @@
 
 /*
  * @test
- * @bug 6347190 8139584
+ * @bug 6347190 8139584 8216408
  * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
  * @run testng/othervm -DrunSecMngr=true stream.XMLStreamWriterTest.XMLStreamWriterTest
  * @run testng/othervm stream.XMLStreamWriterTest.XMLStreamWriterTest
- * @summary Test StAX Writer won't insert comment into element inside.
+ * @summary Tests XMLStreamWriter.
  */
 @Listeners({jaxp.library.BasePolicy.class})
 public class XMLStreamWriterTest {
@@ -94,12 +94,14 @@
     }
 
     /**
-     * Test of main method, of class TestXMLStreamWriter.
+     * Verifies that the StAX Writer won't insert comment into the element tag.
      */
     @Test
     public void testWriteComment() {
         try {
-            String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><a:html href=\"http://java.sun.com\"><!--This is comment-->java.sun.com</a:html>";
+            String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+                    + "<a:html href=\"http://java.sun.com\">"
+                    + "<!--This is comment-->java.sun.com</a:html>";
             XMLOutputFactory f = XMLOutputFactory.newInstance();
             // f.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES,
             // Boolean.TRUE);
@@ -122,4 +124,18 @@
         }
     }
 
+    /**
+     * @bug 8216408
+     * Verifies that setDefaultNamespace accepts null.
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSetDefaultNamespace() throws Exception {
+        XMLOutputFactory f = XMLOutputFactory.newFactory();
+        f.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);
+        StringWriter sw = new StringWriter();
+        XMLStreamWriter xsw = f.createXMLStreamWriter(sw);
+        xsw.setDefaultNamespace(null);
+    }
 }