blob: 39bde6e255bc40ad23e0d530b25fba1cf16512db [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/* @test
25 * @bug 4838379
26 * @summary Verify that custom serialization methods defined by enum types are
27 * not invoked during serialization or deserialization.
28 *
29 * @compile -source 1.5 Test.java
30 * @run main Test
31 */
32
33import java.io.*;
34
35enum Foo {
36
37 foo,
38 bar {
39 private void writeObject(ObjectOutputStream out) throws IOException {
40 throw new Error("bar.writeObject invoked");
41 }
42 private void readObject(ObjectInputStream in)
43 throws IOException, ClassNotFoundException
44 {
45 throw new Error("bar.readObject invoked");
46 }
47 Object writeReplace() throws ObjectStreamException {
48 throw new Error("bar.writeReplace invoked");
49 }
50 // readResolve cannot be defined until Enum.readResolve is removed
51 // Object readResolve() throws ObjectStreamException {
52 // throw new Error("bar.readResolve invoked");
53 // }
54 };
55
56 private void writeObject(ObjectOutputStream out) throws IOException {
57 throw new Error("Foo.writeObject invoked");
58 }
59 private void readObject(ObjectInputStream in)
60 throws IOException, ClassNotFoundException
61 {
62 throw new Error("Foo.readObject invoked");
63 }
64 Object writeReplace() throws ObjectStreamException {
65 throw new Error("Foo.writeReplace invoked");
66 }
67 // readResolve cannot be defined until Enum.readResolve is removed
68 // Object readResolve() throws ObjectStreamException {
69 // throw new Error("Foo.readResolve invoked");
70 // }
71}
72
73public class Test {
74 public static void main(String[] args) throws Exception {
75 ByteArrayOutputStream bout = new ByteArrayOutputStream();
76 ObjectOutputStream oout = new ObjectOutputStream(bout);
77 for (Foo f : Foo.values()) {
78 oout.writeObject(f);
79 }
80 oout.close();
81 ObjectInputStream oin = new ObjectInputStream(
82 new ByteArrayInputStream(bout.toByteArray()));
83 for (Foo f : Foo.values()) {
84 Object obj = oin.readObject();
85 if (obj != f) {
86 throw new Error("expected " + f + ", got " + obj);
87 }
88 }
89 }
90}