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/misplacedArrayClassDesc/MisplacedArrayClassDesc.java
38821 views
1
/*
2
* Copyright (c) 2005, 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
/* @test
25
* @bug 6313687
26
* @summary Verify that if the class descriptor for an ordinary object is the
27
* descriptor for an array class, an ObjectStreamException is thrown.
28
*
29
*/
30
31
import java.io.*;
32
33
class TestArray implements Serializable {
34
// size of array
35
private static final int ARR_SIZE = 5;
36
// serializable field
37
private String[] strArr = new String[ARR_SIZE];
38
39
public TestArray() {
40
for (int i = 0; i < ARR_SIZE; i++) {
41
strArr[i] = "test" + i;
42
}
43
}
44
}
45
46
public class MisplacedArrayClassDesc {
47
public static final void main(String[] args) throws Exception {
48
System.err.println("\nRegression test for CR6313687");
49
TestArray object = new TestArray();
50
try {
51
// Serialize to a byte array
52
ByteArrayOutputStream bos = new ByteArrayOutputStream() ;
53
ObjectOutputStream out = new ObjectOutputStream(bos) ;
54
out.writeObject(object);
55
out.close();
56
57
// Get the bytes of the serialized object
58
byte[] buf = bos.toByteArray();
59
for (int i = 0; i < buf.length; i++) {
60
if (buf[i] == ObjectOutputStream.TC_ARRAY) {
61
buf[i] = ObjectOutputStream.TC_OBJECT;
62
break;
63
}
64
}
65
66
// Deserialize from a byte array
67
ByteArrayInputStream bais = new ByteArrayInputStream(buf);
68
ObjectInputStream in = new ObjectInputStream(bais);
69
TestArray ta = (TestArray) in.readObject();
70
in.close();
71
} catch (InstantiationError e) {
72
throw new Error();
73
} catch (InvalidClassException e) {
74
System.err.println("\nTest passed");
75
return;
76
}
77
throw new Error();
78
}
79
}
80
81