--- /dev/null 2015-12-22 14:26:59.000000000 +0100 +++ new/test/javax/xml/bind/spi/JAXBContextWrapExceptionTest.java 2015-12-22 14:26:59.000000000 +0100 @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2015, 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 8145112 + * @summary newInstance(String,ClassLoader): java.lang.JAXBException should not be wrapped as expected according to spec + * @run main/othervm JAXBContextWrapExceptionTest + */ +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import java.util.Map; + +public class JAXBContextWrapExceptionTest { + + public static class Factory { + + public static JAXBContext createContext(Class[] classesToBeBound, Map properties) throws JAXBException { + throw new JAXBException("test"); + } + + public static JAXBContext createContext(String contextPath, ClassLoader classLoader, Map properties) + throws JAXBException { + throw new JAXBException("test"); + } + } + + public void testContextPath() { + try { + JAXBContext.newInstance("whatever", ClassLoader.getSystemClassLoader()); + fail("This should fail"); + } catch (Throwable t) { + assertEquals("test", t.getMessage()); + assertNull("Root cause must be null", t.getCause()); + } + } + + public void testClasses() { + try { + JAXBContext.newInstance(new Class[0]); + fail("This should fail"); + } catch (Throwable t) { + assertEquals("test", t.getMessage()); + assertNull("Root cause must be null", t.getCause()); + } + } + + public void setup() { + System.setProperty("javax.xml.bind.JAXBContext", "JAXBContextWrapExceptionTest$Factory"); + } + + public static void main(String[] args) throws JAXBException { + JAXBContextWrapExceptionTest tst = new JAXBContextWrapExceptionTest(); + tst.setup(); + tst.testContextPath(); + tst.testClasses(); + } + + private void fail(String msg) { + throw new Error(msg); + } + + private void assertNull(String msg, Object o) { + if (o != null) fail(msg); + } + + private void assertEquals(Object a, Object b) { + + if (a == null) { + if (b != null) fail("AssertEquals failed - expected: [" + a + "], actual: [" + b + "]"); + + } else if (!a.equals(b)) { + fail("AssertEquals failed - expected: [" + a + "], actual: [" + b + "]"); + } + } + +} \ No newline at end of file