Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/Serializable/expectedStackTrace/ExpectedStackTrace.java
41153 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 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
@SuppressWarnings("serial") /* Incorrect declarations are being tested */
46
class SerializableObject extends NotSerializableObject
47
implements Serializable
48
{
49
private static final long serialVersionUID = 1L;
50
51
public SerializableObject(String m_str, Integer m_int) {
52
super(m_str, m_int);
53
}
54
55
public SerializableObject() {
56
super("test", 10);
57
}
58
}
59
60
public class ExpectedStackTrace {
61
private static final String SER_METHOD_NAME = "checkSerializable";
62
63
public static final void main(String[] args) throws Exception {
64
System.err.println("\nRegression test for CRs 6317435, 7110700");
65
checkSerializable(getObject());
66
}
67
68
private static Object getObject() throws Exception {
69
ObjectStreamClass osc =
70
ObjectStreamClass.lookup(SerializableObject.class);
71
SerializableObject initObj =
72
(SerializableObject) osc.forClass().getConstructor().newInstance();
73
return initObj;
74
}
75
76
private static void checkSerializable(Object initObj) throws Exception {
77
try {
78
// Serialize to a byte array
79
ByteArrayOutputStream bos = new ByteArrayOutputStream() ;
80
ObjectOutputStream out = new ObjectOutputStream(bos) ;
81
out.writeObject(initObj);
82
out.close();
83
84
// Get the bytes of the serialized object
85
byte[] buf = bos.toByteArray();
86
87
// Deserialize from a byte array
88
ByteArrayInputStream bais = new ByteArrayInputStream(buf);
89
ObjectInputStream in = new ObjectInputStream(bais);
90
SerializableObject finObj = (SerializableObject) in.readObject();
91
in.close();
92
throw new Error();
93
} catch(ObjectStreamException ex) {
94
StackTraceElement[] stes = ex.getStackTrace();
95
boolean found = false;
96
for (int i = 0; i<stes.length-1; i++) {
97
StackTraceElement ste = stes[i];
98
String nme = ste.getMethodName();
99
if (nme.equals(SER_METHOD_NAME)) {
100
found = true;
101
}
102
}
103
if (found) {
104
if (ex.getCause() != null) {
105
throw new Error("\nTest for CR 7110700 FAILED");
106
}
107
System.err.println("\nTEST PASSED");
108
} else {
109
throw new Error("\nTest for CR 6317435 FAILED");
110
}
111
}
112
}
113
}
114
115