Path: blob/master/test/jdk/java/beans/Beans/Test4067824.java
41152 views
/*1* Copyright (c) 1997, 2007, 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/*24* @test25* @bug 406782426* @summary Tests exception details in Beans.instantiate()27* @author Graham Hamilton28*/2930import java.beans.Beans;31import java.io.FileOutputStream;32import java.io.StreamCorruptedException;3334public class Test4067824 {35public static void main(String[] args) throws Exception {36ClassLoader cl = Test4067824.class.getClassLoader();37try {38Beans.instantiate(cl, "Test4067824");39}40catch (ClassNotFoundException exception) {41// This is expected. Make sure there is the right detail message:42if (exception.toString().indexOf("IllegalAccessException") < 0)43throw new Error("unexpected exception", exception);44}45FileOutputStream fout = new FileOutputStream("foo.ser");46fout.write(new byte [] {1, 2, 3, 4, 5});47fout.close();48try {49// trying to instantiate corrupt foo.ser50Beans.instantiate(cl, "foo");51throw new Error("Instantiated corrupt .ser file OK!!??");52}53catch (ClassNotFoundException exception) {54// expected exception55}56catch (StreamCorruptedException exception) {57// expected exception58}59}6061// private constructor means Beans.instantiate() will fail62private Test4067824() {63}64}656667