Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/io/Serializable/getSuidClinitError/GetSuidClinitError.java
38828 views
/*1* Copyright (c) 2001, 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 448296625* @summary Verify that ObjectStreamClass.getSerialVersionUID() will not mask26* Errors (other than NoSuchMethodError) triggered by JNI query for27* static initializer method.28*/2930import java.io.*;3132class A implements Serializable {33static {34// compiler prohibits direct throw35throwMe(new RuntimeException("blargh"));36}3738static void throwMe(RuntimeException ex) throws RuntimeException {39throw ex;40}41}4243class B implements Serializable {44}4546class C implements Serializable {47static { System.out.println("C.<clinit>"); }48}4950class B1 extends B {51}5253class B2 extends B {54static { System.out.println("B2.<clinit>"); }55}5657class C1 extends C {58}5960class C2 extends C {61static { System.out.println("C2.<clinit>"); }62}6364public class GetSuidClinitError {65public static void main(String[] args) throws Exception {66Class cl = Class.forName(67"A", false, GetSuidClinitError.class.getClassLoader());68for (int i = 0; i < 2; i++) {69try {70ObjectStreamClass.lookup(cl).getSerialVersionUID();71throw new Error();72} catch (ExceptionInInitializerError er) {73} catch (NoClassDefFoundError er) {74/*75* er _should_ be an ExceptionInInitializerError; however,76* hotspot currently throws a NoClassDefFoundError in this77* case, which runs against the JNI spec. For the purposes of78* testing this fix, however, permit either.79*/80System.out.println("warning: caught " + er +81" instead of ExceptionInInitializerError");82}83}8485Class[] cls = new Class[] {86B.class, B1.class, B2.class,87C.class, C1.class, C2.class88};89long[] suids = new long[] { // 1.3.1 default serialVersionUIDs90369445310364440919L, 7585771686008346939L, -8952923334200087495L,913145821251853463625L, 327577314910517070L, -92102021266426451L92};93for (int i = 0; i < cls.length; i++) {94if (ObjectStreamClass.lookup(cls[i]).getSerialVersionUID() !=95suids[i])96{97throw new Error();98}99}100}101}102103104