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 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 { |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
35 |
@SuppressWarnings("serial") /* Incorrect declarations are being tested */ |
2 | 36 |
private static final boolean serialVersionUID = false; |
37 |
} |
|
38 |
||
39 |
class B implements Serializable { |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
40 |
@SuppressWarnings("serial") /* Incorrect declarations are being tested */ |
2 | 41 |
private static final byte serialVersionUID = 5; |
42 |
} |
|
43 |
||
44 |
class C implements Serializable { |
|
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 |
private static final char serialVersionUID = 5; |
47 |
} |
|
48 |
||
49 |
class S implements Serializable { |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
50 |
@SuppressWarnings("serial") /* Incorrect declarations are being tested */ |
2 | 51 |
private static final short serialVersionUID = 5; |
52 |
} |
|
53 |
||
54 |
class I implements Serializable { |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
55 |
@SuppressWarnings("serial") /* Incorrect declarations are being tested */ |
2 | 56 |
private static final int serialVersionUID = 5; |
57 |
} |
|
58 |
||
59 |
class F implements Serializable { |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
60 |
@SuppressWarnings("serial") /* Incorrect declarations are being tested */ |
2 | 61 |
private static final float serialVersionUID = 5.0F; |
62 |
} |
|
63 |
||
64 |
class D implements Serializable { |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
65 |
@SuppressWarnings("serial") /* Incorrect declarations are being tested */ |
2 | 66 |
private static final double serialVersionUID = 5.0; |
67 |
} |
|
68 |
||
69 |
class L implements Serializable { |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
70 |
@SuppressWarnings("serial") /* Incorrect declarations are being tested */ |
2 | 71 |
private static final Object serialVersionUID = "5"; |
72 |
} |
|
73 |
||
74 |
||
75 |
public class BadSerialVersionUID { |
|
76 |
public static void main(String[] args) throws Exception { |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
77 |
Class<?>[] ignore = { Z.class, F.class, D.class, L.class }; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
78 |
Class<?>[] convert = { B.class, C.class, S.class, I.class }; |
2 | 79 |
|
80 |
for (int i = 0; i < ignore.length; i++) { |
|
81 |
ObjectStreamClass.lookup(ignore[i]).getSerialVersionUID(); |
|
82 |
} |
|
83 |
for (int i = 0; i < convert.length; i++) { |
|
84 |
ObjectStreamClass desc = ObjectStreamClass.lookup(convert[i]); |
|
85 |
if (desc.getSerialVersionUID() != 5L) { |
|
86 |
throw new Error(); |
|
87 |
} |
|
88 |
} |
|
89 |
} |
|
90 |
} |