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/expectedStackTrace/ExpectedStackTrace.java
38828 views
1
/*
2
* Copyright (c) 2005, 2011, 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 6317435 7110700
26
* @summary Verify that stack trace contains a proper cause of
27
* InvalidClassException (methods: checkSerialize,
28
* checkDeserialize or checkDefaultSerialize)
29
*
30
* @author Andrey Ozerov
31
*
32
*/
33
import java.io.*;
34
35
class NotSerializableObject {
36
private String m_str;
37
private Integer m_int;
38
39
public NotSerializableObject(String m_str, Integer m_int) {
40
this.m_str = m_str;
41
this.m_int = m_int;
42
}
43
}
44
45
class SerializableObject extends NotSerializableObject
46
implements Serializable
47
{
48
49
public SerializableObject(String m_str, Integer m_int) {
50
super(m_str, m_int);
51
}
52
53
public SerializableObject() {
54
super("test", 10);
55
}
56
}
57
58
public class ExpectedStackTrace {
59
private static final String SER_METHOD_NAME = "checkSerializable";
60
61
public static final void main(String[] args) throws Exception {
62
System.err.println("\nRegression test for CRs 6317435, 7110700");
63
checkSerializable(getObject());
64
}
65
66
private static Object getObject() throws Exception {
67
ObjectStreamClass osc =
68
ObjectStreamClass.lookup(SerializableObject.class);
69
SerializableObject initObj =
70
(SerializableObject) osc.forClass().newInstance();
71
return initObj;
72
}
73
74
private static void checkSerializable(Object initObj) throws Exception {
75
try {
76
// Serialize to a byte array
77
ByteArrayOutputStream bos = new ByteArrayOutputStream() ;
78
ObjectOutputStream out = new ObjectOutputStream(bos) ;
79
out.writeObject(initObj);
80
out.close();
81
82
// Get the bytes of the serialized object
83
byte[] buf = bos.toByteArray();
84
85
// Deserialize from a byte array
86
ByteArrayInputStream bais = new ByteArrayInputStream(buf);
87
ObjectInputStream in = new ObjectInputStream(bais);
88
SerializableObject finObj = (SerializableObject) in.readObject();
89
in.close();
90
throw new Error();
91
} catch(ObjectStreamException ex) {
92
StackTraceElement[] stes = ex.getStackTrace();
93
boolean found = false;
94
for (int i = 0; i<stes.length-1; i++) {
95
StackTraceElement ste = stes[i];
96
String nme = ste.getMethodName();
97
if (nme.equals(SER_METHOD_NAME)) {
98
found = true;
99
}
100
}
101
if (found) {
102
if (ex.getCause() != null) {
103
throw new Error("\nTest for CR 7110700 FAILED");
104
}
105
System.err.println("\nTEST PASSED");
106
} else {
107
throw new Error("\nTest for CR 6317435 FAILED");
108
}
109
}
110
}
111
}
112
113