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

LdapCtx.processReturnCode() throwing Null Pointer Exception

XMLWordPrintable

    • b114
    • x86_64
    • solaris_10

        FULL PRODUCT VERSION :
        java version "1.7.0_72"
        Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
        Java HotSpot(TM) Server VM (build 24.72-b04, mixed mode)


        ADDITIONAL OS VERSION INFORMATION :
        SunOS n3 5.10 Generic_150401-18 i86pc i386 i86pc


        A DESCRIPTION OF THE PROBLEM :
        When an LDAP response is received with status of LdapClient.LDAP_REFERRAL but no referrals are present (and handleReferrals is set to LDAP_REF_THROW), the following exception is received:

        java.lang.NullPointerException
                at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2930)
                at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2840)
                at com.sun.jndi.ldap.LdapNamingEnumeration.getNextBatch(LdapNamingEnumeration.java:147)
                at com.sun.jndi.ldap.LdapNamingEnumeration.hasMoreImpl(LdapNamingEnumeration.java:216)
                at com.sun.jndi.ldap.LdapNamingEnumeration.hasMore(LdapNamingEnumeration.java:189)

        Looking at the source for LdapCtx, res.referrals.elementAt(0) is invoked without first testing that res.referrals is not null. Yes, this is technically an invalid LDAP message, but invalid messages should not result in null pointer exceptions in the stack.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Here is our code snippet that calls into search():

                NamingEnumeration<SearchResult> enumeration = null;

                try
                {
                    setInterruptible(true);
                    scheduleInterruptTimerTask(timer, interruptTimerTask, interruptTimeLimit);

                    enumeration = ldapContext.search(ldapSearchArguments.getDn(), ldapSearchArguments.getFilter(),
                            searchControls);

                    SearchResult searchResult;

                    while (enumeration.hasMore())
                    {
                        searchResult = enumeration.next();
                        returnedAttributes.add(searchResult.getAttributes());
                    }
                }
                finally
                {
                    cancelInterruptTimerTaskAndSetUnInterruptible(interruptTimerTask);
                    closeEnumeration(enumeration);
                }

        As mentioned in the Description, the LDAP response has a status of LdapClient.LDAP_REFERRAL but no referrals are present in the message.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The stack should be throwing some kind of NamingException rather than a null pointer exception.
        ACTUAL -
        See stack trace in Description.

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        See stack trace in Description.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        CUSTOMER SUBMITTED WORKAROUND :
        We currently have to ignore referrals until this bug is fixed (i.e. handleReferrals is set to LDAP_REF_IGNORE).

              coffeys Sean Coffey
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: