MarshalAfterUnexport2.java revision 6244:bd84d0927a2e
1/*
2 * Copyright (c) 2002, 2008, 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 4513223
26 * @summary After an instance of UnicastRemoteObject has been unexported,
27 * if it gets marshalled, an InternalError should not be thrown; instead,
28 * the marshalling should succeed.  Also, if its "local" LiveRef gets
29 * marshalled, by way of the stub returned by RemoteObject.toStub, for
30 * example, then that should also succeed, instead of throwing an
31 * IOException (see fixes for bugids 4353388, 4017232).  This test
32 * handles the case where the impl's RemoteRef is a UnicastServerRef2.
33 * @author Peter Jones
34 * @author Ann Wollrath
35 *
36 * @build MarshalAfterUnexport2 MarshalAfterUnexport2_Stub
37 * @run main/othervm MarshalAfterUnexport2
38 */
39
40import java.rmi.MarshalledObject;
41import java.rmi.Remote;
42import java.rmi.RemoteException;
43import java.rmi.server.RemoteObject;
44import java.rmi.server.UnicastRemoteObject;
45
46public class MarshalAfterUnexport2
47    extends UnicastRemoteObject
48    implements Receiver
49{
50    public MarshalAfterUnexport2() throws RemoteException {
51        super(0, null, null);
52    }
53
54    public void receive(Remote obj) {
55    }
56
57    public static void main(String[] args) throws Exception {
58
59        System.err.println("\nRegression test for bug 4513223\n");
60
61        Remote impl2 = null;
62        try {
63            Remote impl = new MarshalAfterUnexport2();
64            System.err.println(
65                "created impl extending URO (with a UnicastServerRef2): " +
66                impl);
67
68            Receiver stub = (Receiver) RemoteObject.toStub(impl);
69            System.err.println("stub for impl: " + stub);
70
71            UnicastRemoteObject.unexportObject(impl, true);
72            System.err.println("unexported impl");
73
74            impl2 = new MarshalAfterUnexport2();
75            Receiver stub2 = (Receiver) RemoteObject.toStub(impl2);
76
77            System.err.println("marshalling unexported object:");
78            MarshalledObject mobj = new MarshalledObject(impl);
79
80            System.err.println("passing unexported object via RMI-JRMP:");
81            stub2.receive(stub);
82
83            System.err.println("TEST PASSED");
84        } finally {
85            if (impl2 != null) {
86                try {
87                    UnicastRemoteObject.unexportObject(impl2, true);
88                } catch (Throwable t) {
89                }
90            }
91        }
92    }
93}
94
95interface Receiver extends Remote {
96    void receive(Remote obj) throws RemoteException;
97}
98