Path: blob/master/test/jdk/java/io/Serializable/getSuidClinitError/GetSuidClinitError.java
41154 views
/*1* Copyright (c) 2001, 2019, 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.*;3132@SuppressWarnings("serial") /* Incorrect declarations are being tested. */33class A implements Serializable {34static {35// compiler prohibits direct throw36throwMe(new RuntimeException("blargh"));37}3839static void throwMe(RuntimeException ex) throws RuntimeException {40throw ex;41}42}4344@SuppressWarnings("serial") /* Incorrect declarations are being tested. */45class B implements Serializable {46}4748@SuppressWarnings("serial") /* Incorrect declarations are being tested. */49class C implements Serializable {50static { System.out.println("C.<clinit>"); }51}5253@SuppressWarnings("serial") /* Incorrect declarations are being tested. */54class B1 extends B {55}5657@SuppressWarnings("serial") /* Incorrect declarations are being tested. */58class B2 extends B {59static { System.out.println("B2.<clinit>"); }60}6162@SuppressWarnings("serial") /* Incorrect declarations are being tested. */63class C1 extends C {64}6566@SuppressWarnings("serial") /* Incorrect declarations are being tested. */67class C2 extends C {68static { System.out.println("C2.<clinit>"); }69}7071public class GetSuidClinitError {72public static void main(String[] args) throws Exception {73Class<?> cl = Class.forName(74"A", false, GetSuidClinitError.class.getClassLoader());75for (int i = 0; i < 2; i++) {76try {77ObjectStreamClass.lookup(cl).getSerialVersionUID();78throw new Error();79} catch (ExceptionInInitializerError er) {80} catch (NoClassDefFoundError er) {81/*82* er _should_ be an ExceptionInInitializerError; however,83* hotspot currently throws a NoClassDefFoundError in this84* case, which runs against the JNI spec. For the purposes of85* testing this fix, however, permit either.86*/87System.out.println("warning: caught " + er +88" instead of ExceptionInInitializerError");89}90}9192Class<?>[] cls = {93B.class, B1.class, B2.class,94C.class, C1.class, C2.class95};96long[] suids = new long[] { // 1.3.1 default serialVersionUIDs97369445310364440919L, 7585771686008346939L, -8952923334200087495L,983145821251853463625L, 327577314910517070L, -92102021266426451L99};100for (int i = 0; i < cls.length; i++) {101if (ObjectStreamClass.lookup(cls[i]).getSerialVersionUID() !=102suids[i])103{104throw new Error();105}106}107}108}109110111