Bug6350682.java revision 779:2b61bfcaa586
1/*
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24package common;
25
26import javax.xml.parsers.SAXParserFactory;
27import javax.xml.transform.TransformerFactory;
28import javax.xml.transform.TransformerFactoryConfigurationError;
29
30import org.testng.Assert;
31import org.testng.annotations.Test;
32
33/*
34 * @bug 6350682
35 * @summary Test SAXParserFactory and TransformerFactory can newInstance when setContextClassLoader(null).
36 */
37public class Bug6350682 {
38
39    @Test
40    public void testSAXParserFactory() {
41        try {
42            Thread.currentThread().setContextClassLoader(null);
43            if (Bug6350682.class.getClassLoader() == null)
44                System.out.println("this class loader is NULL");
45            else
46                System.out.println("this class loader is NOT NULL");
47            SAXParserFactory factory = SAXParserFactory.newInstance();
48            Assert.assertTrue(factory != null, "Failed to get an instance of a SAXParserFactory");
49        } catch (Exception e) {
50            e.printStackTrace();
51            Assert.fail("Exception occured: " + e.getMessage());
52        }
53    }
54
55    @Test
56    public void testTransformerFactory() {
57        try {
58            Thread.currentThread().setContextClassLoader(null);
59            TransformerFactory factory = TransformerFactory.newInstance();
60            Assert.assertTrue(factory != null, "Failed to get an instance of a TransformerFactory");
61        } catch (Exception e) {
62            e.printStackTrace();
63            Assert.fail("Exception occured: " + e.getMessage());
64        } catch (TransformerFactoryConfigurationError error) {
65            error.printStackTrace();
66            Assert.fail(error.toString());
67        }
68    }
69}
70