Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/Serializable/getSuidClinitError/GetSuidClinitError.java
41154 views
1
/*
2
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
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
*
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.
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
@SuppressWarnings("serial") /* Incorrect declarations are being tested. */
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
45
@SuppressWarnings("serial") /* Incorrect declarations are being tested. */
46
class B implements Serializable {
47
}
48
49
@SuppressWarnings("serial") /* Incorrect declarations are being tested. */
50
class C implements Serializable {
51
static { System.out.println("C.<clinit>"); }
52
}
53
54
@SuppressWarnings("serial") /* Incorrect declarations are being tested. */
55
class B1 extends B {
56
}
57
58
@SuppressWarnings("serial") /* Incorrect declarations are being tested. */
59
class B2 extends B {
60
static { System.out.println("B2.<clinit>"); }
61
}
62
63
@SuppressWarnings("serial") /* Incorrect declarations are being tested. */
64
class C1 extends C {
65
}
66
67
@SuppressWarnings("serial") /* Incorrect declarations are being tested. */
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 {
74
Class<?> cl = Class.forName(
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
93
Class<?>[] cls = {
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
}
110
111