LegacyChainedExceptionSerialization.java revision 2362
d3ed5b56cb6b58f87ffd125bed48f7668f13de1edirkx/*
893328ef6ff86d0ca27774778d84410353789fb0fielding * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
842ae4bd224140319ae7feec1872b93dfd491143fielding * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
842ae4bd224140319ae7feec1872b93dfd491143fielding *
842ae4bd224140319ae7feec1872b93dfd491143fielding * This code is free software; you can redistribute it and/or modify it
842ae4bd224140319ae7feec1872b93dfd491143fielding * under the terms of the GNU General Public License version 2 only, as
842ae4bd224140319ae7feec1872b93dfd491143fielding * published by the Free Software Foundation.
842ae4bd224140319ae7feec1872b93dfd491143fielding *
893328ef6ff86d0ca27774778d84410353789fb0fielding * This code is distributed in the hope that it will be useful, but WITHOUT
0202d2114cc6d7042995100519cce45c808c153bnd * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
893328ef6ff86d0ca27774778d84410353789fb0fielding * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0202d2114cc6d7042995100519cce45c808c153bnd * version 2 for more details (a copy is included in the LICENSE file that
0202d2114cc6d7042995100519cce45c808c153bnd * accompanied this code).
0202d2114cc6d7042995100519cce45c808c153bnd *
0202d2114cc6d7042995100519cce45c808c153bnd * You should have received a copy of the GNU General Public License version
0202d2114cc6d7042995100519cce45c808c153bnd * 2 along with this work; if not, write to the Free Software Foundation,
893328ef6ff86d0ca27774778d84410353789fb0fielding * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
893328ef6ff86d0ca27774778d84410353789fb0fielding *
893328ef6ff86d0ca27774778d84410353789fb0fielding * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
893328ef6ff86d0ca27774778d84410353789fb0fielding * or visit www.oracle.com if you need additional information or have any
0d50a692ff2ac7bdb42e417737ed86ebf0a41671ben * questions.
14eccd0082c748ae3464dc2459430ff0772b5107sf */
14eccd0082c748ae3464dc2459430ff0772b5107sf
14eccd0082c748ae3464dc2459430ff0772b5107sfimport java.io.*;
14eccd0082c748ae3464dc2459430ff0772b5107sf
14eccd0082c748ae3464dc2459430ff0772b5107sf/**
14eccd0082c748ae3464dc2459430ff0772b5107sf * @test
14eccd0082c748ae3464dc2459430ff0772b5107sf * @bug 4385429
14eccd0082c748ae3464dc2459430ff0772b5107sf * @summary Certain legacy chained exceptions throw IllegalArgumentException
14eccd0082c748ae3464dc2459430ff0772b5107sf * upon deserialization if "causative exception" is null.
14eccd0082c748ae3464dc2459430ff0772b5107sf * @author Josh Bloch
14eccd0082c748ae3464dc2459430ff0772b5107sf */
14eccd0082c748ae3464dc2459430ff0772b5107sfpublic class LegacyChainedExceptionSerialization {
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz private static Throwable[] broken = {
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz new ClassNotFoundException(),
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz new ExceptionInInitializerError(),
90b402e944318ae02afd50911eae6da1910f661dpquerna new java.lang.reflect.UndeclaredThrowableException(null),
928f622b54e87afbbaba6add8aef8066ca16a040wrowe new java.lang.reflect.InvocationTargetException(null),
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz new java.security.PrivilegedActionException(null),
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz new java.awt.print.PrinterIOException(null)
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz };
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz public static void main(String[] args) throws Exception {
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz for (int i=0; i<broken.length; i++)
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz test(broken[i]);
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz }
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz private static void test(Throwable e) throws Exception {
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz ByteArrayOutputStream bout = new ByteArrayOutputStream();
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz ObjectOutputStream out = new ObjectOutputStream(bout);
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz out.writeObject(e);
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz out.flush();
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz ByteArrayInputStream bin =
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz new ByteArrayInputStream(bout.toByteArray());
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz ObjectInputStream in = new ObjectInputStream(bin);
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz Throwable clone = (Throwable) in.readObject();
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz }
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz}
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz