Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/io/Serializable/cloneArray/CloneArray.java
38828 views
1
/*
2
* Copyright (c) 2010, 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 6990094
27
* @summary Verify ObjectInputStream.cloneArray works on many kinds of arrays
28
* @author Stuart Marks, Joseph D. Darcy
29
*/
30
31
import java.io.ByteArrayInputStream;
32
import java.io.ByteArrayOutputStream;
33
import java.io.IOException;
34
import java.io.ObjectInputStream;
35
import java.io.ObjectOutputStream;
36
import java.io.ObjectStreamException;
37
import java.io.Serializable;
38
39
public class CloneArray {
40
static Object replacement;
41
42
static class Resolver implements Serializable {
43
private Object readResolve() throws ObjectStreamException {
44
return replacement;
45
}
46
}
47
48
private static void test(Object rep)
49
throws IOException, ClassNotFoundException {
50
51
try(ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
52
try(ObjectOutputStream oos = new ObjectOutputStream(baos)) {
53
oos.writeObject(new Resolver());
54
oos.writeObject(new Resolver());
55
}
56
57
Object o1;
58
Object o2;
59
try(ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
60
ObjectInputStream ois = new ObjectInputStream(bais)) {
61
replacement = rep;
62
o1 = ois.readUnshared();
63
o2 = ois.readUnshared();
64
}
65
66
if (o1 == o2)
67
throw new AssertionError("o1 and o2 must not be identical");
68
}
69
}
70
71
public static void main(String[] args)
72
throws IOException, ClassNotFoundException {
73
Object[] replacements = {
74
new byte[] {1},
75
new char[] {'2'},
76
new short[] {3},
77
new int[] {4},
78
new long[] {5},
79
new float[] {6.0f},
80
new double[] {7.0},
81
new boolean[] {true},
82
new Object[] {"A string."}
83
};
84
85
for(Object replacement : replacements) {
86
test(replacement);
87
}
88
}
89
}
90
91