1/*
2 * Copyright (c) 2001, 2012, 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 4353388
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 fix for bugid 4017232).
32 * @author Peter Jones
33 *
34 * @build MarshalAfterUnexport MarshalAfterUnexport_Stub
35 * @run main/othervm MarshalAfterUnexport
36 */
37
38import java.rmi.MarshalledObject;
39import java.rmi.Remote;
40import java.rmi.RemoteException;
41import java.rmi.server.RemoteObject;
42import java.rmi.server.UnicastRemoteObject;
43
44public class MarshalAfterUnexport
45    extends UnicastRemoteObject
46    implements Receiver
47{
48    public MarshalAfterUnexport() throws RemoteException {
49    }
50
51    public void receive(Remote obj) {
52    }
53
54    public static void main(String[] args) throws Exception {
55        Remote impl2 = null;
56        try {
57            Remote impl = new MarshalAfterUnexport();
58            System.err.println("created impl extending URO: " + impl);
59
60            Receiver stub = (Receiver) RemoteObject.toStub(impl);
61            System.err.println("stub for impl: " + stub);
62
63            UnicastRemoteObject.unexportObject(impl, true);
64            System.err.println("unexported impl");
65
66            impl2 = new MarshalAfterUnexport();
67            Receiver stub2 = (Receiver) RemoteObject.toStub(impl2);
68
69            System.err.println("marshalling unexported object:");
70            MarshalledObject mobj = new MarshalledObject(impl);
71
72            System.err.println("passing unexported object via RMI-JRMP:");
73            stub2.receive(stub);
74
75            System.err.println("TEST PASSED");
76        } finally {
77            if (impl2 != null) {
78                try {
79                    UnicastRemoteObject.unexportObject(impl2, true);
80                } catch (Throwable t) {
81                }
82            }
83        }
84    }
85}
86
87interface Receiver extends Remote {
88    void receive(Remote obj) throws RemoteException;
89}
90