Mercurial > hg > icedtea7-forest > jdk
changeset 6852:cd7a4d0b218f jdk7u40-b36
8021148: Regression in SAXParserImpl in 7u40 b34 (NPE)
Reviewed-by: chegar, lancea, dfuchs
author | joehw |
---|---|
date | Thu, 25 Jul 2013 18:13:14 -0700 |
parents | 3136030959da |
children | 0721089b469e 46b203b37e06 4c6eb1390566 |
files | test/javax/xml/jaxp/parsers/8021148/JAXPSAXParserTest.java test/javax/xml/jaxp/parsers/8021148/TestBase.java |
diffstat | 2 files changed, 195 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/xml/jaxp/parsers/8021148/JAXPSAXParserTest.java Thu Jul 25 18:13:14 2013 -0700 @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2013, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8021148 + * @summary test that JAXPSAXParser works even if referenced directly + * @run main/othervm JAXPSAXParserTest + */ +import java.io.StringReader; +import java.io.StringWriter; +import javax.xml.transform.Result; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +/** + * test that JAXPSAXParser works even if referenced directly as + * NetBeans did. **Note that JAXPSAXParser is an internal implementation, this + * may therefore change. + * + * @author huizhe.wang@oracle.com + */ +public class JAXPSAXParserTest extends TestBase { + + public JAXPSAXParserTest(String name) { + super(name); + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + JAXPSAXParserTest test = new JAXPSAXParserTest("JAXP 1.5 regression"); + test.setUp(); + test.testTransform(); + test.tearDown(); + } + + public final void testTransform() { + String data = + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + + "<r>\n" + + " <e/>\n" + + "</r>\n"; + String IDENTITY_XSLT_WITH_INDENT = // #5064280 workaround + "<xsl:stylesheet version='1.0' " + + "xmlns:xsl='http://www.w3.org/1999/XSL/Transform' " + + "xmlns:xalan='http://xml.apache.org/xslt' " + + "exclude-result-prefixes='xalan'>" + + "<xsl:output method='xml' indent='yes' xalan:indent-amount='4'/>" + + "<xsl:template match='@*|node()'>" + + "<xsl:copy>" + + "<xsl:apply-templates select='@*|node()'/>" + + "</xsl:copy>" + + "</xsl:template>" + + "</xsl:stylesheet>"; + try { + //Skip the default XMLReader + System.setProperty("org.xml.sax.driver", "com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser"); + + StringWriter sw = new StringWriter(); + TransformerFactory tf = TransformerFactory.newInstance(); + Transformer t = tf.newTransformer(new StreamSource(new StringReader(IDENTITY_XSLT_WITH_INDENT))); + Result result = new StreamResult(sw); + t.transform(new StreamSource(new StringReader(data)), result); + success("JAXPSAXParserTest passed"); + } catch (Exception e) { + /** + * JAXPSAXParser throws NullPointerException since the jaxp 1.5 security + * manager is not initialized when JAXPSAXParser is instantiated using + * the default constructor. + */ + fail(e.toString()); + } finally { + System.clearProperty("org.xml.sax.driver"); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/xml/jaxp/parsers/8021148/TestBase.java Thu Jul 25 18:13:14 2013 -0700 @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2013, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.security.Policy; + +/** + * + * + * @author huizhe.wang@oracle.com + */ +public class TestBase { + String filePath; + boolean hasSM; + String curDir; + Policy origPolicy; + + String testName; + static String errMessage; + + int passed = 0, failed = 0; + + /** + * Creates a new instance of StreamReader + */ + public TestBase(String name) { + testName = name; + } + + //junit @Override + protected void setUp() { + if (System.getSecurityManager() != null) { + hasSM = true; + System.setSecurityManager(null); + } + + filePath = System.getProperty("test.src"); + if (filePath == null) { + //current directory + filePath = System.getProperty("user.dir"); + } + origPolicy = Policy.getPolicy(); + + } + + //junit @Override + public void tearDown() { + // turn off security manager and restore policy + System.setSecurityManager(null); + Policy.setPolicy(origPolicy); + if (hasSM) { + System.setSecurityManager(new SecurityManager()); + } + System.out.println("\nNumber of tests passed: " + passed); + System.out.println("Number of tests failed: " + failed + "\n"); + + if (errMessage != null ) { + throw new RuntimeException(errMessage); + } + } + + void fail(String errMsg) { + if (errMessage == null) { + errMessage = errMsg; + } else { + errMessage = errMessage + "\n" + errMsg; + } + failed++; + } + + void success(String msg) { + passed++; + System.out.println(msg); + } + +}