1 /* |
1 /* |
2 * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved. |
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. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
30 */ |
30 */ |
31 |
31 |
32 import java.io.*; |
32 import java.io.*; |
33 |
33 |
34 class Z implements Serializable { |
34 class Z implements Serializable { |
|
35 @SuppressWarnings("serial") /* Incorrect declarations are being tested */ |
35 private static final boolean serialVersionUID = false; |
36 private static final boolean serialVersionUID = false; |
36 } |
37 } |
37 |
38 |
38 class B implements Serializable { |
39 class B implements Serializable { |
|
40 @SuppressWarnings("serial") /* Incorrect declarations are being tested */ |
39 private static final byte serialVersionUID = 5; |
41 private static final byte serialVersionUID = 5; |
40 } |
42 } |
41 |
43 |
42 class C implements Serializable { |
44 class C implements Serializable { |
|
45 @SuppressWarnings("serial") /* Incorrect declarations are being tested */ |
43 private static final char serialVersionUID = 5; |
46 private static final char serialVersionUID = 5; |
44 } |
47 } |
45 |
48 |
46 class S implements Serializable { |
49 class S implements Serializable { |
|
50 @SuppressWarnings("serial") /* Incorrect declarations are being tested */ |
47 private static final short serialVersionUID = 5; |
51 private static final short serialVersionUID = 5; |
48 } |
52 } |
49 |
53 |
50 class I implements Serializable { |
54 class I implements Serializable { |
|
55 @SuppressWarnings("serial") /* Incorrect declarations are being tested */ |
51 private static final int serialVersionUID = 5; |
56 private static final int serialVersionUID = 5; |
52 } |
57 } |
53 |
58 |
54 class F implements Serializable { |
59 class F implements Serializable { |
|
60 @SuppressWarnings("serial") /* Incorrect declarations are being tested */ |
55 private static final float serialVersionUID = 5.0F; |
61 private static final float serialVersionUID = 5.0F; |
56 } |
62 } |
57 |
63 |
58 class D implements Serializable { |
64 class D implements Serializable { |
|
65 @SuppressWarnings("serial") /* Incorrect declarations are being tested */ |
59 private static final double serialVersionUID = 5.0; |
66 private static final double serialVersionUID = 5.0; |
60 } |
67 } |
61 |
68 |
62 class L implements Serializable { |
69 class L implements Serializable { |
|
70 @SuppressWarnings("serial") /* Incorrect declarations are being tested */ |
63 private static final Object serialVersionUID = "5"; |
71 private static final Object serialVersionUID = "5"; |
64 } |
72 } |
65 |
73 |
66 |
74 |
67 public class BadSerialVersionUID { |
75 public class BadSerialVersionUID { |
68 public static void main(String[] args) throws Exception { |
76 public static void main(String[] args) throws Exception { |
69 Class[] ignore = { Z.class, F.class, D.class, L.class }; |
77 Class<?>[] ignore = { Z.class, F.class, D.class, L.class }; |
70 Class[] convert = { B.class, C.class, S.class, I.class }; |
78 Class<?>[] convert = { B.class, C.class, S.class, I.class }; |
71 |
79 |
72 for (int i = 0; i < ignore.length; i++) { |
80 for (int i = 0; i < ignore.length; i++) { |
73 ObjectStreamClass.lookup(ignore[i]).getSerialVersionUID(); |
81 ObjectStreamClass.lookup(ignore[i]).getSerialVersionUID(); |
74 } |
82 } |
75 for (int i = 0; i < convert.length; i++) { |
83 for (int i = 0; i < convert.length; i++) { |