public static void main(String[] args) throws Exception {

    System.err.println("\nRegression test for bug 4513223\n");

    Remote impl2 = null;
    try {
      Remote impl = new MarshalAfterUnexport2();
      System.err.println("created impl extending URO (with a UnicastServerRef2): " + impl);

      Receiver stub = (Receiver) RemoteObject.toStub(impl);
      System.err.println("stub for impl: " + stub);

      UnicastRemoteObject.unexportObject(impl, true);
      System.err.println("unexported impl");

      impl2 = new MarshalAfterUnexport2();
      Receiver stub2 = (Receiver) RemoteObject.toStub(impl2);

      System.err.println("marshalling unexported object:");
      MarshalledObject mobj = new MarshalledObject(impl);

      System.err.println("passing unexported object via RMI-JRMP:");
      stub2.receive(stub);

      System.err.println("TEST PASSED");
    } finally {
      if (impl2 != null) {
        try {
          UnicastRemoteObject.unexportObject(impl2, true);
        } catch (Throwable t) {
        }
      }
    }
  }
 RmiDebuggerService() {
   try {
     debugger = new RmiDebuggerImpl(this);
     server = new DebuggerServer((Serializable) RemoteObject.toStub(debugger));
     server.start();
   } catch (RemoteException e) {
     e.printStackTrace();
     throw new UndeclaredThrowableException(e);
   }
 }
 /**
  * Returns a serializable stub for this {@link RMIServer} object.
  *
  * @return a serializable stub.
  * @exception IOException if the stub cannot be obtained - e.g the RMIJRMPServerImpl has not been
  *     exported yet.
  */
 public Remote toStub() throws IOException {
   return RemoteObject.toStub(this);
 }