Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/Throwable/LegacyChainedExceptionSerialization.java
38812 views
/*1* Copyright (c) 2000, 2012, 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*/2223import java.io.*;2425/**26* @test27* @bug 4385429 800492828* @summary Certain legacy chained exceptions throw IllegalArgumentException29* upon deserialization if "causative exception" is null.30* @author Josh Bloch31*/32public class LegacyChainedExceptionSerialization {33private static Throwable[] broken = {34new ClassNotFoundException(),35new ExceptionInInitializerError(),36new java.lang.reflect.UndeclaredThrowableException(null),37new java.lang.reflect.InvocationTargetException(null),38new java.security.PrivilegedActionException(null)39};4041public static void main(String[] args) throws Exception {42for (int i=0; i<broken.length; i++)43test(broken[i]);44}4546private static void test(Throwable e) throws Exception {47ByteArrayOutputStream bout = new ByteArrayOutputStream();48ObjectOutputStream out = new ObjectOutputStream(bout);49out.writeObject(e);50out.flush();5152ByteArrayInputStream bin =53new ByteArrayInputStream(bout.toByteArray());54ObjectInputStream in = new ObjectInputStream(bin);55Throwable clone = (Throwable) in.readObject();56}57}585960