2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2001, 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 |
|
|
33 |
class A implements Serializable {
|
|
34 |
static {
|
|
35 |
// compiler prohibits direct throw
|
|
36 |
throwMe(new RuntimeException("blargh"));
|
|
37 |
}
|
|
38 |
|
|
39 |
static void throwMe(RuntimeException ex) throws RuntimeException {
|
|
40 |
throw ex;
|
|
41 |
}
|
|
42 |
}
|
|
43 |
|
|
44 |
class B implements Serializable {
|
|
45 |
}
|
|
46 |
|
|
47 |
class C implements Serializable {
|
|
48 |
static { System.out.println("C.<clinit>"); }
|
|
49 |
}
|
|
50 |
|
|
51 |
class B1 extends B {
|
|
52 |
}
|
|
53 |
|
|
54 |
class B2 extends B {
|
|
55 |
static { System.out.println("B2.<clinit>"); }
|
|
56 |
}
|
|
57 |
|
|
58 |
class C1 extends C {
|
|
59 |
}
|
|
60 |
|
|
61 |
class C2 extends C {
|
|
62 |
static { System.out.println("C2.<clinit>"); }
|
|
63 |
}
|
|
64 |
|
|
65 |
public class GetSuidClinitError {
|
|
66 |
public static void main(String[] args) throws Exception {
|
|
67 |
Class cl = Class.forName(
|
|
68 |
"A", false, GetSuidClinitError.class.getClassLoader());
|
|
69 |
for (int i = 0; i < 2; i++) {
|
|
70 |
try {
|
|
71 |
ObjectStreamClass.lookup(cl).getSerialVersionUID();
|
|
72 |
throw new Error();
|
|
73 |
} catch (ExceptionInInitializerError er) {
|
|
74 |
} catch (NoClassDefFoundError er) {
|
|
75 |
/*
|
|
76 |
* er _should_ be an ExceptionInInitializerError; however,
|
|
77 |
* hotspot currently throws a NoClassDefFoundError in this
|
|
78 |
* case, which runs against the JNI spec. For the purposes of
|
|
79 |
* testing this fix, however, permit either.
|
|
80 |
*/
|
|
81 |
System.out.println("warning: caught " + er +
|
|
82 |
" instead of ExceptionInInitializerError");
|
|
83 |
}
|
|
84 |
}
|
|
85 |
|
|
86 |
Class[] cls = new Class[] {
|
|
87 |
B.class, B1.class, B2.class,
|
|
88 |
C.class, C1.class, C2.class
|
|
89 |
};
|
|
90 |
long[] suids = new long[] { // 1.3.1 default serialVersionUIDs
|
|
91 |
369445310364440919L, 7585771686008346939L, -8952923334200087495L,
|
|
92 |
3145821251853463625L, 327577314910517070L, -92102021266426451L
|
|
93 |
};
|
|
94 |
for (int i = 0; i < cls.length; i++) {
|
|
95 |
if (ObjectStreamClass.lookup(cls[i]).getSerialVersionUID() !=
|
|
96 |
suids[i])
|
|
97 |
{
|
|
98 |
throw new Error();
|
|
99 |
}
|
|
100 |
}
|
|
101 |
}
|
|
102 |
}
|