|
| 1 | +/* |
| 2 | + * @test /nodynamiccopyright/ |
| 3 | + * @bug 8312415 |
| 4 | + * @compile/ref=ClassBody.out -XDrawDiagnostics -Xlint:serial EnumExternClassBody.java |
| 5 | + * @compile/ref=empty.out -XDrawDiagnostics EnumExternClassBody.java |
| 6 | + */ |
| 7 | + |
| 8 | +import java.io.*; |
| 9 | + |
| 10 | +/* |
| 11 | + * Verify warnings are generated as appropriate for enum constants |
| 12 | + * with specialized class bodies. |
| 13 | + */ |
| 14 | +class EnumExternClassBody { |
| 15 | + |
| 16 | + /* |
| 17 | + * Define externalization methods both in the enum class and a |
| 18 | + * specialized enum constant. |
| 19 | + */ |
| 20 | + private static enum ColorExtern1 implements Externalizable { |
| 21 | + RED( 0xFF_00_00), |
| 22 | + GREEN(0x00_FF_00), |
| 23 | + BLUE( 0x00_00_FF) { |
| 24 | + @Override |
| 25 | + public void readExternal(ObjectInput in) { |
| 26 | + throw new RuntimeException(); |
| 27 | + } |
| 28 | + |
| 29 | + @Override |
| 30 | + public void writeExternal(ObjectOutput out) throws IOException { |
| 31 | + throw new RuntimeException(); |
| 32 | + } |
| 33 | + |
| 34 | + // Look for serialization members too |
| 35 | + private static final long serialVersionUID = 42; |
| 36 | + private static final ObjectStreamField[] serialPersistentFields = {}; |
| 37 | + |
| 38 | + private void writeObject(ObjectOutputStream stream) throws IOException { |
| 39 | + throw new RuntimeException(); |
| 40 | + } |
| 41 | + |
| 42 | + private Object writeReplace() throws ObjectStreamException { |
| 43 | + return null; |
| 44 | + } |
| 45 | + |
| 46 | + private void readObject(ObjectInputStream stream) |
| 47 | + throws IOException, ClassNotFoundException { |
| 48 | + throw new RuntimeException(); |
| 49 | + } |
| 50 | + |
| 51 | + private void readObjectNoData() throws ObjectStreamException { |
| 52 | + return; |
| 53 | + } |
| 54 | + |
| 55 | + private Object readResolve() throws ObjectStreamException { |
| 56 | + return null; |
| 57 | + } |
| 58 | + }; |
| 59 | + |
| 60 | + int rgb; |
| 61 | + private ColorExtern1(int rgb) { |
| 62 | + this.rgb = rgb; |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + public void readExternal(ObjectInput in) { |
| 67 | + throw new RuntimeException(); |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public void writeExternal(ObjectOutput out) throws IOException { |
| 72 | + throw new RuntimeException(); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + /* |
| 77 | + * Define externalization methods only on specialized enum |
| 78 | + * constants. |
| 79 | + */ |
| 80 | + private static enum ColorExtern2 implements Externalizable { |
| 81 | + CYAN { |
| 82 | + @Override |
| 83 | + public void readExternal(ObjectInput in) { |
| 84 | + throw new RuntimeException(); |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public void writeExternal(ObjectOutput out) throws IOException { |
| 89 | + throw new RuntimeException(); |
| 90 | + } |
| 91 | + }; |
| 92 | + } |
| 93 | + |
| 94 | + /* |
| 95 | + * Define externalization methods only on specialized enum |
| 96 | + * constants. |
| 97 | + */ |
| 98 | + private static enum ColorExtern3 implements Externalizable { |
| 99 | + MAGENTA { |
| 100 | + @Override |
| 101 | + public void readExternal(ObjectInput in) { |
| 102 | + throw new RuntimeException(); |
| 103 | + } |
| 104 | + |
| 105 | + @Override |
| 106 | + public void writeExternal(ObjectOutput out) throws IOException { |
| 107 | + throw new RuntimeException(); |
| 108 | + } |
| 109 | + }; |
| 110 | + |
| 111 | + // Acceptable to have ineffectual warnings for these abstract methods |
| 112 | + public abstract void readExternal(ObjectInput in); |
| 113 | + public abstract void writeExternal(ObjectOutput out) throws IOException ; |
| 114 | + } |
| 115 | +} |
0 commit comments