Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/io/Serializable/badSerialVersionUID/BadSerialVersionUID.java
38821 views
1
/*
2
* Copyright (c) 2001, 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 4431318
26
* @summary Verify that when serialVersionUID is declared with a type other
27
* than long, values that can be promoted to long will be used, and
28
* those that can't be will be ignored (but will not result in
29
* unchecked exceptions).
30
*/
31
32
import java.io.*;
33
34
class Z implements Serializable {
35
private static final boolean serialVersionUID = false;
36
}
37
38
class B implements Serializable {
39
private static final byte serialVersionUID = 5;
40
}
41
42
class C implements Serializable {
43
private static final char serialVersionUID = 5;
44
}
45
46
class S implements Serializable {
47
private static final short serialVersionUID = 5;
48
}
49
50
class I implements Serializable {
51
private static final int serialVersionUID = 5;
52
}
53
54
class F implements Serializable {
55
private static final float serialVersionUID = 5.0F;
56
}
57
58
class D implements Serializable {
59
private static final double serialVersionUID = 5.0;
60
}
61
62
class L implements Serializable {
63
private static final Object serialVersionUID = "5";
64
}
65
66
67
public class BadSerialVersionUID {
68
public static void main(String[] args) throws Exception {
69
Class[] ignore = { Z.class, F.class, D.class, L.class };
70
Class[] convert = { B.class, C.class, S.class, I.class };
71
72
for (int i = 0; i < ignore.length; i++) {
73
ObjectStreamClass.lookup(ignore[i]).getSerialVersionUID();
74
}
75
for (int i = 0; i < convert.length; i++) {
76
ObjectStreamClass desc = ObjectStreamClass.lookup(convert[i]);
77
if (desc.getSerialVersionUID() != 5L) {
78
throw new Error();
79
}
80
}
81
}
82
}
83
84