8216408: XMLStreamWriter setDefaultNamespace(null) throws NullPointerException

Reviewed-by: dfuchs, lancea
This commit is contained in:
Joe Wang 2019-01-25 14:28:43 -08:00
parent 23931d94f7
commit 1ebe11a28d
2 changed files with 24 additions and 12 deletions

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -44,6 +44,7 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import javax.xml.XMLConstants; import javax.xml.XMLConstants;
@ -1729,12 +1730,7 @@ public final class XMLStreamWriterImpl extends AbstractMap<Object, Object>
*/ */
private boolean isDefaultNamespace(String uri) { private boolean isDefaultNamespace(String uri) {
String defaultNamespace = fInternalNamespaceContext.getURI(DEFAULT_PREFIX); String defaultNamespace = fInternalNamespaceContext.getURI(DEFAULT_PREFIX);
return Objects.equals(uri, defaultNamespace);
if (uri.equals(defaultNamespace)) {
return true;
}
return false;
} }
/** /**

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -42,11 +42,11 @@ import org.w3c.dom.Document;
/* /*
* @test * @test
* @bug 6347190 8139584 * @bug 6347190 8139584 8216408
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
* @run testng/othervm -DrunSecMngr=true stream.XMLStreamWriterTest.XMLStreamWriterTest * @run testng/othervm -DrunSecMngr=true stream.XMLStreamWriterTest.XMLStreamWriterTest
* @run testng/othervm 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}) @Listeners({jaxp.library.BasePolicy.class})
public class XMLStreamWriterTest { public class XMLStreamWriterTest {
@ -94,12 +94,14 @@ public class XMLStreamWriterTest {
} }
/** /**
* Test of main method, of class TestXMLStreamWriter. * Verifies that the StAX Writer won't insert comment into the element tag.
*/ */
@Test @Test
public void testWriteComment() { public void testWriteComment() {
try { 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(); XMLOutputFactory f = XMLOutputFactory.newInstance();
// f.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, // f.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES,
// Boolean.TRUE); // Boolean.TRUE);
@ -122,4 +124,18 @@ public class XMLStreamWriterTest {
} }
} }
/**
* @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);
}
} }