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

RMI lookup doesn't throw correct exception when no registry listener on the port

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Future Project
    • Icon: P4 P4
    • tbd
    • 5.0
    • core-libs

      Basically in jdk1.4.x, the RMI lookup returns a catchable exception (e.g. ConnectException), however, in jdk1.5.0-beta it's throwing an Error
      when there is no registry listener on that port. This only happens when the lookup() is done from a shutdown hook. Anyway, in our case, this
      means that notifyCompleted() is never called, which causes our application to hang since the second shutdown hook is waiting on the first. The
      application also seems to have a hard hang.. On my Windows 2000 box, I can no longer ctrl-c to quit the app.. I need to actually kill it explicitly.
       

       
      ======
       
      import java.rmi.Naming;
       
      class ShutdownTest extends Thread
      {
        // specify whether this hook should run first
        private boolean runMeFirst;
       
        private static boolean ranFirstAlready = false;
       
        public static final void main(String[] argv)
        {
          ShutdownTest st1 = new ShutdownTest(false);
          ShutdownTest st2 = new ShutdownTest(true);
          Runtime.getRuntime().addShutdownHook(st1);
          Runtime.getRuntime().addShutdownHook(st2);
          System.out.println("Finished main");
        }
       
        public ShutdownTest(boolean runfirst)
        {
          runMeFirst = runfirst;
        }
       
        public void run()
        {
          if ((!runMeFirst) && (!getRanFirstAlready()))
          {
            waitUntilCompleted();
          }
          System.out.println("Before lookup");
          try
          {
            //throw new Error("test");
            Object obj = Naming.lookup("rmi://localhost:9999/anything");
          }
          catch (Exception ex)
          {
            ex.printStackTrace();
          }
          System.out.println("After lookup");
          notifyCompleted();
        }
       
        public static synchronized void waitUntilCompleted()
        {
          while (ranFirstAlready == false)
          {
            try
            {
              ShutdownTest.class.wait();
            }
            catch (InterruptedException ex)
            {
            }
          }
        }
        public static synchronized void notifyCompleted()
        {
          ranFirstAlready = true;
          ShutdownTest.class.notifyAll();
        }
       
        public synchronized boolean getRanFirstAlready()
        {
          return ranFirstAlready;
        }
      }

            Unassigned Unassigned
            mmma Marvin Ma (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: