[Date Prev][Date Next] [Chronological] [Thread] [Top]

Potential Java LDAPEntry bug when searching with invalid DN.

Good Afternoon OpenLDAP list,

I have been working with some java code and found what I think may be a bug.  If it isn't a bug, then I believe that the documentation should be updated to describe this behavior.  I create an LDAPConnection and attempt a search with an invalid search base.  The search function returns an LDAPSearchResults that is not null and results.hasMore() returns true.  Because there are results we print the number of results and attempt to print them.  The call to results.next() causes an exception.  The behavior I expected is to throw an exception on the search itself.  It seems very misleading to be told that there are entries and then have an exception thrown when the program attempts to analyze them.  If this behavior is expected, then is there a better way of detecting an invalid search base as a workaround?

Here is the relevant piece of code and my output.

    try {
        boolean attributeOnly = true;
        String attrs[] = { LDAPConnection.NO_ATTRS };
        int searchScope = LDAPConnection.SCOPE_ONE;
        String searchBase = "invalid dn";
        String searchFilter = "(objectclass=*)";

        LDAPSearchResults results = null;

        results = lc.search(searchBase, searchScope, searchFilter, attrs, attributeOnly);
        if (results != null && results.hasMore()) {
          System.out.println("search yielded " + results.getCount() + " results");
          while (results.hasMore()) {
            LDAPEntry entry = results.next();
            System.out.println("Got entry");
      System.out.println (lc.read("").toString());
    } catch (LDAPException e) {
      System.out.println ("Could not search: " + e);

and the output

search yielded 1 results
Could not search: LDAPException: Invalid DN Syntax (34) Invalid DN Syntax
LDAPException: Server Message: Invalid DN
LDAPException: Matched DN:

Many Thanks,
Tim Nowaczyk

Timothy Nowaczyk
Network Systems Engineer
University of Virginia - ITC

Attachment: smime.p7s
Description: S/MIME cryptographic signature