Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/Serializable/misplacedArrayClassDesc/MisplacedArrayClassDesc.java
41152 views
1
/*
2
* Copyright (c) 2005, 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
/* @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
private static final long serialVersionUID = 1L;
35
36
// size of array
37
private static final int ARR_SIZE = 5;
38
// serializable field
39
private String[] strArr = new String[ARR_SIZE];
40
41
public TestArray() {
42
for (int i = 0; i < ARR_SIZE; i++) {
43
strArr[i] = "test" + i;
44
}
45
}
46
}
47
48
public class MisplacedArrayClassDesc {
49
public static final void main(String[] args) throws Exception {
50
System.err.println("\nRegression test for CR6313687");
51
TestArray object = new TestArray();
52
try {
53
// Serialize to a byte array
54
ByteArrayOutputStream bos = new ByteArrayOutputStream() ;
55
ObjectOutputStream out = new ObjectOutputStream(bos) ;
56
out.writeObject(object);
57
out.close();
58
59
// Get the bytes of the serialized object
60
byte[] buf = bos.toByteArray();
61
for (int i = 0; i < buf.length; i++) {
62
if (buf[i] == ObjectOutputStream.TC_ARRAY) {
63
buf[i] = ObjectOutputStream.TC_OBJECT;
64
break;
65
}
66
}
67
68
// Deserialize from a byte array
69
ByteArrayInputStream bais = new ByteArrayInputStream(buf);
70
ObjectInputStream in = new ObjectInputStream(bais);
71
TestArray ta = (TestArray) in.readObject();
72
in.close();
73
} catch (InstantiationError e) {
74
throw new Error();
75
} catch (InvalidClassException e) {
76
System.err.println("\nTest passed");
77
return;
78
}
79
throw new Error();
80
}
81
}
82
83