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

Sun's Ldap Jndi provide doesn't use javax.naming.InterruptedNamingException

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.4.1
    • core-libs

      Name: nt126004 Date: 02/07/2003


      FULL PRODUCT VERSION :
      java version "1.4.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
      Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)


      FULL OPERATING SYSTEM VERSION :
      SunOS pegasus 5.8 Generic_108528-17 sun4u sparc
      SUNW,Sun-Fire-280R


      A DESCRIPTION OF THE PROBLEM :
      Sun's Ldap Jndi provide doen't use
      javax.naming.InterruptedNamingException when you interrupt a
      thread waiting responses from an ldap server.
      It uses the generic NamingException and the cause isnt even
      initialised to an InterruptedIOException.
      Even worse the Thread.interrupted() is cleared by the time
      the exception is caught.
      The only way to determine that the cause was interruption is to
      check if the NamingExceptions message contains
      InterruptedIOException.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Run the source code attached

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      The actual results are:

      Connecting
      NamingException
      No root cause javax.naming.CommunicationException:
      www.google.com:389 [Root exception is
      java.io.InterruptedIOException: operation interrupted]
      Am I interrupted false


      Ideally an InterruptedNamingException would be caught
      instead of a generic NamingException.

      Otherwise the NamingExceptions root cause should be the
      InterruptedIOException. (This will have issues with java 1.3
      of course.)

      Otherwise at the very least Thread.interrupted() state
      should still be valid.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      import java.util.*;
      import javax.naming.*;
      import javax.naming.directory.*;

      public class InterruptTest extends Thread {
          
          static Thread mainThread;
          
          public static void main(String[] args) {

      mainThread = Thread.currentThread();

      new InterruptTest().start();

      try {
      Hashtable environment = new Hashtable();
      environment.put(DirContext.INITIAL_CONTEXT_FACTORY,
      "com.sun.jndi.ldap.LdapCtxFactory");
      environment.put(DirContext.PROVIDER_URL, "ldap://www.google.com");

      System.out.println("Connecting");

      DirContext context = new InitialDirContext(environment);
      }
      catch(InterruptedNamingException e) {
      System.out.println("InterruptedNamingException");
      }
      catch(NamingException e) {
      System.out.println("NamingException");
      if(e.getCause()!=null) {
      System.out.println("Root cause class " + getRootCause(e).getClass());
      }
      else {
      System.out.println("No root cause " + e);
      }
      System.out.println("Am I interrupted " + Thread.interrupted());
      }
          }
          
          public static Throwable getRootCause(Throwable t) {
      Throwable cause = t.getCause();
      if(cause==null) {
      return t;
      }
      else {
      return getRootCause(cause);
      }
          }
          
          public void run() {
      try {
      Thread.sleep(5000);
      }
      catch(InterruptedException e) {
      }
      mainThread.interrupt();
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      The only way to determine the cause was interruption is to
      check if the NamingExceptions message contains
      InterruptedIOException.
      (Review ID: 180872)
      ======================================================================

            vtewari Vyom Tewari
            nthompsosunw Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: