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/rmi/activation/Activatable/notSerializable/NotSerializable.java
38829 views
1
/*
2
* Copyright (c) 2003, 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 4460983
26
* @summary This test verifies that an instance of Activatable cannot
27
* be serialized (without implicit impl-to-stub replacement), because
28
* it cannot be meaningfully deserialized anyway.
29
* See also test/java/rmi/server/RemoteObject/unrecognizedRefType.
30
* @author Peter Jones
31
*
32
* @run main/othervm NotSerializable
33
*/
34
35
import java.io.ByteArrayOutputStream;
36
import java.io.NotSerializableException;
37
import java.io.ObjectInput;
38
import java.io.ObjectOutputStream;
39
import java.io.ObjectOutput;
40
import java.lang.reflect.Method;
41
import java.rmi.MarshalledObject;
42
import java.rmi.NoSuchObjectException;
43
import java.rmi.Remote;
44
import java.rmi.RemoteException;
45
import java.rmi.server.Operation;
46
import java.rmi.server.RemoteCall;
47
import java.rmi.server.RemoteObject;
48
import java.rmi.server.RemoteRef;
49
import java.rmi.server.RemoteStub;
50
import java.rmi.activation.Activatable;
51
import java.rmi.activation.ActivationID;
52
import java.rmi.activation.Activator;
53
54
public class NotSerializable {
55
56
public static void main(String[] args) throws Exception {
57
System.err.println("\nRegression test for bug 4460983\n");
58
59
Activatable act = new FakeActivatable();
60
try {
61
ObjectOutputStream out =
62
new ObjectOutputStream(new ByteArrayOutputStream());
63
try {
64
out.writeObject(act);
65
throw new RuntimeException("TEST FAILED: " +
66
"Activatable instance successfully serialized");
67
} catch (NotSerializableException e) {
68
System.err.println("NotSerializableException as expected:");
69
e.printStackTrace();
70
} // other exceptions cause test failure
71
72
System.err.println("TEST PASSED");
73
} finally {
74
try {
75
Activatable.unexportObject(act, true);
76
} catch (NoSuchObjectException e) {
77
}
78
}
79
}
80
81
private static class FakeActivatable extends Activatable {
82
FakeActivatable() throws RemoteException {
83
super(new ActivationID(new FakeActivator()), 0);
84
}
85
}
86
87
private static class FakeActivator
88
extends RemoteStub implements Activator
89
{
90
FakeActivator() {
91
super(new FakeRemoteRef("FakeRef"));
92
}
93
94
public MarshalledObject activate(ActivationID id, boolean force) {
95
return null;
96
}
97
}
98
99
private static class FakeRemoteRef implements RemoteRef {
100
private final String refType;
101
102
FakeRemoteRef(String refType) {
103
this.refType = refType;
104
}
105
106
public Object invoke(Remote obj,
107
Method method,
108
Object[] params,
109
long opnum)
110
{
111
throw new UnsupportedOperationException();
112
}
113
114
public RemoteCall newCall(RemoteObject obj,
115
Operation[] op,
116
int opnum,
117
long hash)
118
{
119
throw new UnsupportedOperationException();
120
}
121
122
public void invoke(RemoteCall call) {
123
throw new UnsupportedOperationException();
124
}
125
126
public void done(RemoteCall call) {
127
throw new UnsupportedOperationException();
128
}
129
130
public String getRefClass(java.io.ObjectOutput out) {
131
return refType;
132
}
133
134
public int remoteHashCode() { return hashCode(); }
135
public boolean remoteEquals(RemoteRef obj) { return equals(obj); }
136
public String remoteToString() { return toString(); }
137
138
public void readExternal(ObjectInput in) {
139
throw new UnsupportedOperationException();
140
}
141
142
public void writeExternal(ObjectOutput out) {
143
// no data to write
144
}
145
}
146
}
147
148