Path: blob/master/test/jdk/java/rmi/RemoteException/chaining/Chaining.java
41152 views
/*1* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 441697025* @summary test chained exception support26* @run main/othervm Chaining27*/28import java.rmi.MarshalledObject;29import java.rmi.RemoteException;30import java.rmi.server.ServerCloneException;3132public class Chaining {33static void check(Throwable t, String msg, Throwable cause)34throws Exception35{36String tmsg = t.getMessage();37if (msg == null ? tmsg != null : !msg.equals(tmsg)) {38throw new RuntimeException("message does not match");39}40if (t.getClass().getField("detail").get(t) != cause) {41throw new RuntimeException("detail field does not match");42}43if (t.getCause() != cause) {44throw new RuntimeException("getCause value does not match");45}46try {47t.initCause(cause);48throw new RuntimeException("initCause succeeded");49} catch (IllegalStateException e) {50}51}5253static void test(Throwable t, String msg, Throwable cause)54throws Exception55{56check(t, msg, cause);57Throwable[] pair = new Throwable[]{t, cause};58pair = (Throwable[]) new MarshalledObject(pair).get();59check(pair[0], msg, pair[1]);60}6162public static void main(String[] args) throws Exception {63Exception t = new RuntimeException();64String foo = "foo";65String fooMsg = "foo; nested exception is: \n\t" + t;66test(new RemoteException(), null, null);67test(new RemoteException(foo), foo, null);68test(new RemoteException(foo, t), fooMsg, t);69test(new ServerCloneException(foo), foo, null);70test(new ServerCloneException(foo, t), fooMsg, t);71}72}737475