4 Replies Latest reply on Nov 4, 2009 8:29 AM by EJP

    hasMore() throws a NullPointerException

    843793
      I've got the following exception:

      java.lang.NullPointerException
      at com.sun.jndi.ldap.LdapCtx.getSearchReply(Unknown Source)
      at com.sun.jndi.ldap.LdapNamingEnumeration.getNextBatch(Unknown Source)
      at com.sun.jndi.ldap.LdapNamingEnumeration.hasMoreImpl(Unknown Source)
      at com.sun.jndi.ldap.LdapNamingEnumeration.hasMore(Unknown Source)

      My java version is 1.6.

      Here after is my code:

      public boolean isConnectionLost()
      {
      /* setting search constraints based on in-param */
      String[] attrs = new String[0];
      SearchControls constraints = new SearchControls();
      constraints.setSearchScope(SearchControls.OBJECT_SCOPE);
      constraints.setReturningAttributes(attrs);
      constraints.setCountLimit(1);

      try
      {
      NamingEnumeration<SearchResult> result = searchNative("", "(objectclass=*)", attrs,
      constraints);
      /* NOTE!!! JNDI will leak connections if this loop is not performed. */
      while (result != null && result.hasMore())
      {
      result.next();
      }
      }
      catch (StorageException e)
      {
      if (e.getNamingException() != null)
      {
      return true;
      }     
      }
      catch (NamingException e)
      {
      // Thrown by hasMore() and/or next();
      sLogger.system.debug("Failed to iterate search results, {0}", e);
      }
      return false;
      }




      I saw on the forum, but it was quite old (2005-2006) that a guy get the same exception and it does happen when he called hasMore() after a while loop that reach the end... But the answer wasn't explicit on the problem (it was suggested to catch the null pointer exception...).

      Curiously, if I change the while into an if, the problem disappears... Note that I should have only one ressource on my request (constraints.setCountLimit(1);).

      Does anyone have a clue?