Closed Bug 31141 Opened 26 years ago Closed 26 years ago

LDAPSearchResults getCount() method returns incorrect value

Categories

(Directory Graveyard :: LDAP Java SDK, defect, P3)

x86
Windows NT
defect

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: joerg.schaefer, Assigned: miodrag)

Details

Attachments

(1 file)

In the code snippet below, I want to use getCount() to check how many entries are returned in the search result "res" in order to reject authentication in case of multiple entries. However, getCount() always incorrectly returns 0 (see line "System.out.println(res.getCount());"). A strange thing happens when I debug the code (I am running Jbuilder V3.0), the correct value (1 in our case) is returned in this case (and printed to System.out)! I am using NT4.00.1381 Netscape Directory Java SDK 4.0 Borland Jbuilder V3.0 //Code Snippet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% try{ ld.connect(MY_HOST, MY_PORT); LDAPSearchResults res = ld.search(MY_SEARCHBASE, LDAPConnection.SCOPE_SUB, MY_FILTER, null, false); // should include code for checking for multiple entries, but getCount() does not work System.out.println(res.getCount()); if(res.getCount()!=0){ if(res.hasMoreElements()){ findEntry = res.next(); dn = findEntry.getDN(); ld.authenticate(dn, pwd); status = true; if (ld.isConnected()) { try { ld.disconnect(); } catch ( LDAPException e ) {throw e;} } } } } catch(LDAPException e){ if(e.getLDAPResultCode() == LDAPException.INVALID_CREDENTIALS){ return status; } else{throw e;} } catch(Exception x){x.printStackTrace();} return status; }
Reassigned to Miodrag.
Assignee: mcs → miodrag
This is a normal behavior. LDAPSearchResults.getCount() returns the number of currently available search results in the search result queue, rather than the total number of entries that match the search filter. When the directory sends a new search result, the result gets queued and the search result count is incremented. As you read search results from LDAPSearchResults, one at a time, the search result count gets decremeneted. Only if you set the batch size in LDAPSearchConstrains to 0 --means search() should wait for all results to be received before proceeding --, you'll see the exact count of found entries. By default the batchSize is 1, which means results are to be processed as they come in. LDAPSearchResults.hasMoreElements() blocks until the batchSize number of results is received.
Status: NEW → RESOLVED
Closed: 26 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: