ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/Collections/Ser.java
Revision: 1.4
Committed: Mon Jan 8 03:12:03 2018 UTC (6 years, 3 months ago) by jsr166
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +7 -2 lines
Log Message:
organize imports

File Contents

# Content
1 /*
2 * Copyright (c) 1999, 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 /*
25 * @test
26 * @bug 4190323
27 * @summary EMPTY_SET, EMPTY_LIST, and the collections returned by
28 * nCopies and singleton were spec'd to be serializable, but weren't.
29 */
30
31 import java.io.ByteArrayInputStream;
32 import java.io.ByteArrayOutputStream;
33 import java.io.ObjectInputStream;
34 import java.io.ObjectOutputStream;
35 import java.util.Collections;
36 import java.util.List;
37 import java.util.Set;
38
39 public class Ser {
40 public static void main(String[] args) throws Exception {
41
42 try {
43 ByteArrayOutputStream bos = new ByteArrayOutputStream();
44 ObjectOutputStream out = new ObjectOutputStream(bos);
45 out.writeObject(Collections.EMPTY_SET);
46 out.flush();
47 ObjectInputStream in = new ObjectInputStream(
48 new ByteArrayInputStream(bos.toByteArray()));
49
50 if (!Collections.EMPTY_SET.equals(in.readObject()))
51 throw new RuntimeException("empty set Ser/Deser failure.");
52 } catch (Exception e) {
53 throw new RuntimeException("Failed to serialize empty set:" + e);
54 }
55
56 try {
57 ByteArrayOutputStream bos = new ByteArrayOutputStream();
58 ObjectOutputStream out = new ObjectOutputStream(bos);
59 out.writeObject(Collections.EMPTY_LIST);
60 out.flush();
61 ObjectInputStream in = new ObjectInputStream(
62 new ByteArrayInputStream(bos.toByteArray()));
63
64 if (!Collections.EMPTY_LIST.equals(in.readObject()))
65 throw new RuntimeException("empty list Ser/Deser failure.");
66 } catch (Exception e) {
67 throw new RuntimeException("Failed to serialize empty list:" + e);
68 }
69
70 try {
71 ByteArrayOutputStream bos = new ByteArrayOutputStream();
72 ObjectOutputStream out = new ObjectOutputStream(bos);
73 Set gumby = Collections.singleton("gumby");
74 out.writeObject(gumby);
75 out.flush();
76 ObjectInputStream in = new ObjectInputStream(
77 new ByteArrayInputStream(bos.toByteArray()));
78
79 if (!gumby.equals(in.readObject()))
80 throw new RuntimeException("Singleton Ser/Deser failure.");
81 } catch (Exception e) {
82 throw new RuntimeException("Failed to serialize singleton:" + e);
83 }
84
85 try {
86 ByteArrayOutputStream bos = new ByteArrayOutputStream();
87 ObjectOutputStream out = new ObjectOutputStream(bos);
88 List gumbies = Collections.nCopies(50, "gumby");
89 out.writeObject(gumbies);
90 out.flush();
91 ObjectInputStream in = new ObjectInputStream(
92 new ByteArrayInputStream(bos.toByteArray()));
93
94 if (!gumbies.equals(in.readObject()))
95 throw new RuntimeException("nCopies Ser/Deser failure.");
96 } catch (Exception e) {
97 throw new RuntimeException("Failed to serialize nCopies:" + e);
98 }
99 }
100 }