8152530: NullPointerException when xmlns=""
Reviewed-by: dfuchs, naoto, lancea
This commit is contained in:
parent
e91b43837d
commit
b414bb7023
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2005, 2016, 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
|
||||||
@ -305,9 +305,12 @@ public class StAXStream2SAX implements XMLReader, Locator {
|
|||||||
if (prefix == null) { // true for default namespace
|
if (prefix == null) { // true for default namespace
|
||||||
prefix = "";
|
prefix = "";
|
||||||
}
|
}
|
||||||
_sax.startPrefixMapping(
|
String uri = staxStreamReader.getNamespaceURI(i);
|
||||||
prefix,
|
if (uri == null && prefix.isEmpty()) { // true for default namespace
|
||||||
staxStreamReader.getNamespaceURI(i));
|
uri = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
_sax.startPrefixMapping(prefix, uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fire startElement
|
// fire startElement
|
||||||
|
@ -30,7 +30,9 @@ import javax.xml.stream.XMLEventReader;
|
|||||||
import javax.xml.stream.XMLEventWriter;
|
import javax.xml.stream.XMLEventWriter;
|
||||||
import javax.xml.stream.XMLInputFactory;
|
import javax.xml.stream.XMLInputFactory;
|
||||||
import javax.xml.stream.XMLOutputFactory;
|
import javax.xml.stream.XMLOutputFactory;
|
||||||
|
import javax.xml.stream.XMLStreamConstants;
|
||||||
import javax.xml.stream.XMLStreamException;
|
import javax.xml.stream.XMLStreamException;
|
||||||
|
import javax.xml.stream.XMLStreamReader;
|
||||||
import javax.xml.transform.Transformer;
|
import javax.xml.transform.Transformer;
|
||||||
import javax.xml.transform.TransformerConfigurationException;
|
import javax.xml.transform.TransformerConfigurationException;
|
||||||
import javax.xml.transform.TransformerException;
|
import javax.xml.transform.TransformerException;
|
||||||
@ -38,6 +40,7 @@ import javax.xml.transform.TransformerFactory;
|
|||||||
import javax.xml.transform.dom.DOMResult;
|
import javax.xml.transform.dom.DOMResult;
|
||||||
import javax.xml.transform.stax.StAXResult;
|
import javax.xml.transform.stax.StAXResult;
|
||||||
import javax.xml.transform.stax.StAXSource;
|
import javax.xml.transform.stax.StAXSource;
|
||||||
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.Listeners;
|
import org.testng.annotations.Listeners;
|
||||||
@ -45,6 +48,7 @@ import org.testng.annotations.Test;
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
|
* @bug 8152530
|
||||||
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
|
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
|
||||||
* @run testng/othervm -DrunSecMngr=true transform.StAXSourceTest
|
* @run testng/othervm -DrunSecMngr=true transform.StAXSourceTest
|
||||||
* @run testng/othervm transform.StAXSourceTest
|
* @run testng/othervm transform.StAXSourceTest
|
||||||
@ -52,6 +56,33 @@ import org.testng.annotations.Test;
|
|||||||
*/
|
*/
|
||||||
@Listeners({jaxp.library.FilePolicy.class})
|
@Listeners({jaxp.library.FilePolicy.class})
|
||||||
public class StAXSourceTest {
|
public class StAXSourceTest {
|
||||||
|
/**
|
||||||
|
* @bug 8152530
|
||||||
|
* Verifies that StAXSource handles empty namespace properly. NPE was thrown
|
||||||
|
* before the fix.
|
||||||
|
* @throws Exception if the test fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public final void testStAXSourceWEmptyNS() throws Exception {
|
||||||
|
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||||
|
+ "<EntityList>\n"
|
||||||
|
+ " <Entity xmlns=\"\">\n"
|
||||||
|
+ " </Entity>\n"
|
||||||
|
+ " <Entity xmlns=\"\">\n"
|
||||||
|
+ " </Entity>\n"
|
||||||
|
+ "</EntityList> ";
|
||||||
|
|
||||||
|
XMLInputFactory xif = XMLInputFactory.newInstance();
|
||||||
|
XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(xml));
|
||||||
|
xsr.nextTag();
|
||||||
|
TransformerFactory tf = TransformerFactory.newInstance();
|
||||||
|
Transformer t = tf.newTransformer();
|
||||||
|
while (xsr.nextTag() == XMLStreamConstants.START_ELEMENT && xsr.getLocalName().equals("Entity")) {
|
||||||
|
StringWriter stringResult = new StringWriter();
|
||||||
|
t.transform(new StAXSource(xsr), new StreamResult(stringResult));
|
||||||
|
System.out.println("result: \n" + stringResult.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public final void testStAXSource() throws XMLStreamException {
|
public final void testStAXSource() throws XMLStreamException {
|
||||||
|
Loading…
Reference in New Issue
Block a user