Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/Serializable/cloneArray/CloneArray.java
41154 views
1
/*
2
* Copyright (c) 2010, 2019, 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 static final long serialVersionUID = 1L;
44
45
private Object readResolve() throws ObjectStreamException {
46
return replacement;
47
}
48
}
49
50
private static void test(Object rep)
51
throws IOException, ClassNotFoundException {
52
53
try(ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
54
try(ObjectOutputStream oos = new ObjectOutputStream(baos)) {
55
oos.writeObject(new Resolver());
56
oos.writeObject(new Resolver());
57
}
58
59
Object o1;
60
Object o2;
61
try(ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
62
ObjectInputStream ois = new ObjectInputStream(bais)) {
63
replacement = rep;
64
o1 = ois.readUnshared();
65
o2 = ois.readUnshared();
66
}
67
68
if (o1 == o2)
69
throw new AssertionError("o1 and o2 must not be identical");
70
}
71
}
72
73
public static void main(String[] args)
74
throws IOException, ClassNotFoundException {
75
Object[] replacements = {
76
new byte[] {1},
77
new char[] {'2'},
78
new short[] {3},
79
new int[] {4},
80
new long[] {5},
81
new float[] {6.0f},
82
new double[] {7.0},
83
new boolean[] {true},
84
new Object[] {"A string."}
85
};
86
87
for(Object replacement : replacements) {
88
test(replacement);
89
}
90
}
91
}
92
93