author | rriggs |
Fri, 11 Oct 2019 13:11:56 -0400 | |
changeset 58565 | baa5969ecf34 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* @test |
|
25 |
* @bug 4482966 |
|
26 |
* @summary Verify that ObjectStreamClass.getSerialVersionUID() will not mask |
|
27 |
* Errors (other than NoSuchMethodError) triggered by JNI query for |
|
28 |
* static initializer method. |
|
29 |
*/ |
|
30 |
||
31 |
import java.io.*; |
|
32 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
33 |
@SuppressWarnings("serial") /* Incorrect declarations are being tested. */ |
2 | 34 |
class A implements Serializable { |
35 |
static { |
|
36 |
// compiler prohibits direct throw |
|
37 |
throwMe(new RuntimeException("blargh")); |
|
38 |
} |
|
39 |
||
40 |
static void throwMe(RuntimeException ex) throws RuntimeException { |
|
41 |
throw ex; |
|
42 |
} |
|
43 |
} |
|
44 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
45 |
@SuppressWarnings("serial") /* Incorrect declarations are being tested. */ |
2 | 46 |
class B implements Serializable { |
47 |
} |
|
48 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
49 |
@SuppressWarnings("serial") /* Incorrect declarations are being tested. */ |
2 | 50 |
class C implements Serializable { |
51 |
static { System.out.println("C.<clinit>"); } |
|
52 |
} |
|
53 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
54 |
@SuppressWarnings("serial") /* Incorrect declarations are being tested. */ |
2 | 55 |
class B1 extends B { |
56 |
} |
|
57 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
58 |
@SuppressWarnings("serial") /* Incorrect declarations are being tested. */ |
2 | 59 |
class B2 extends B { |
60 |
static { System.out.println("B2.<clinit>"); } |
|
61 |
} |
|
62 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
63 |
@SuppressWarnings("serial") /* Incorrect declarations are being tested. */ |
2 | 64 |
class C1 extends C { |
65 |
} |
|
66 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
67 |
@SuppressWarnings("serial") /* Incorrect declarations are being tested. */ |
2 | 68 |
class C2 extends C { |
69 |
static { System.out.println("C2.<clinit>"); } |
|
70 |
} |
|
71 |
||
72 |
public class GetSuidClinitError { |
|
73 |
public static void main(String[] args) throws Exception { |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
74 |
Class<?> cl = Class.forName( |
2 | 75 |
"A", false, GetSuidClinitError.class.getClassLoader()); |
76 |
for (int i = 0; i < 2; i++) { |
|
77 |
try { |
|
78 |
ObjectStreamClass.lookup(cl).getSerialVersionUID(); |
|
79 |
throw new Error(); |
|
80 |
} catch (ExceptionInInitializerError er) { |
|
81 |
} catch (NoClassDefFoundError er) { |
|
82 |
/* |
|
83 |
* er _should_ be an ExceptionInInitializerError; however, |
|
84 |
* hotspot currently throws a NoClassDefFoundError in this |
|
85 |
* case, which runs against the JNI spec. For the purposes of |
|
86 |
* testing this fix, however, permit either. |
|
87 |
*/ |
|
88 |
System.out.println("warning: caught " + er + |
|
89 |
" instead of ExceptionInInitializerError"); |
|
90 |
} |
|
91 |
} |
|
92 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
93 |
Class<?>[] cls = { |
2 | 94 |
B.class, B1.class, B2.class, |
95 |
C.class, C1.class, C2.class |
|
96 |
}; |
|
97 |
long[] suids = new long[] { // 1.3.1 default serialVersionUIDs |
|
98 |
369445310364440919L, 7585771686008346939L, -8952923334200087495L, |
|
99 |
3145821251853463625L, 327577314910517070L, -92102021266426451L |
|
100 |
}; |
|
101 |
for (int i = 0; i < cls.length; i++) { |
|
102 |
if (ObjectStreamClass.lookup(cls[i]).getSerialVersionUID() != |
|
103 |
suids[i]) |
|
104 |
{ |
|
105 |
throw new Error(); |
|
106 |
} |
|
107 |
} |
|
108 |
} |
|
109 |
} |