Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4060069

Naming.lookup fails with java.rmi.UnmarshalException: Error unmarshaling return

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1
    • core-libs
    • None
    • x86
    • windows_nt



      Name: mc57594 Date: 06/19/97


      A call to Naming.lookup will sometimes improperly fail with the following error:

      java.rmi.UnmarshalException: Error unmarshaling return header

      at sun.rmi.transport.StreamRemoteCall.executeCall(
      StreamRemoteCall.java:208)

      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:104)

      at sun.rmi.registry.RegistryImpl_Stub.lookup( RegistryImpl_Stub.java:94)

      at java.rmi.Naming.lookup(Naming.java:60)

      The following source code reproduces the problem:

      -------------------------------MyClient.java------------------------------------
      import java.rmi.server.*;
      import java.rmi.*;
      import java.rmi.registry.*;
      import java.io.*;

      // simple rmi client
      import com.meitca.hsl.zonesjagents.security.*;

      public class MyClient {
        public static void main(String args[]) {
          System.setSecurityManager(new InsecurityManager());

          DataInputStream istream = new DataInputStream(System.in);
          while (true) {
            try {
              istream.readLine();
              MyServer server = (MyServer) Naming.lookup("MyServer");

              for (int i=0; i<10; i++) {
                int j = server.hello(i);
                System.out.println(j);
              }
            } catch (Exception e) {
              System.out.println("Exception during test");
              System.err.println(e.getMessage());
              e.printStackTrace();
            }
          }
        }
      }
      ----------------------------------------------------------------------------------------

      --------------------------------MyServer.java----------------------------------
      import java.rmi.Remote;
      import java.rmi.RemoteException;

      interface MyServer extends Remote {
        public int hello(int num) throws RemoteException;
      }
      ----------------------------------------------------------------------------------------

      -------------------------------MyServerImpl.java----------------------------
      import java.rmi.server.*;
      import java.rmi.*;
      import java.rmi.registry.*;

      import com.meitca.hsl.zonesjagents.security.*;

      // server implementation
      public class MyServerImpl
          extends UnicastRemoteObject
          implements MyServer {

        public MyServerImpl() throws RemoteException {
        }

        public int hello(int num) throws RemoteException {
          return num;
        }

        public static void main(String args[]) {
          System.setSecurityManager(new InsecurityManager());
       
          try {
            // start the registry
            LocateRegistry.createRegistry(Registry.REGISTRY_PORT);

            MyServerImpl server = new MyServerImpl();

            Naming.rebind("MyServer", server);

          } catch (Exception e) {
            System.out.println("Exception during test");
            System.err.println(e.getMessage());
            e.printStackTrace();
          }
        }
      }
      ----------------------------------------------------------------------------------------


      To reproduce the problem do the following:

      1) Run the MyServerImpl
      2) Run the MyClient
      3) Hit the Enter key in the MyClient window. You will see the numbers 0 to 9 on the screen (up to now it works fine).
      4) Now kill the MyServerImpl via a Control-C
      5) Restart the MyServerImpl a second time (DO NOT RESTART THE MyClient!)
      6) Give the Server some time to intialize and then hit Enter again in MyClient
      7) The Error listed above will be reported.
      8) Hit Enter again in MyClient
      9) The Error listed above will be reported a second time.
      10) Hit Enter a thrid time.
      11) This time the program will work and you will see the numbers 0 to 9 on the screen

      The call to Naming.lookup is failing even though at the time of the call, a new MyServerImpl object has been created and has bound itself to the name "MyServer".

      This problem seems to be related to the fact that the Registry is created within the MyServerImpl VM, and thus the Registry is stopped when that VM is Control-C'd. If the Registry is run as a seperate VM (using rmiregistry.exe) the Exception does not occur.

      Running the Registry in a sperate VM is not an acceptable workaround for us do to product requirements.

      ======================================================================

            awollratsunw Ann Wollrath (Inactive)
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: