Results 1 to 2 of 2

Thread: filter.encode NullPointerException

  1. #1

    Question filter.encode NullPointerException

    Hi everyone,

    I am using Spring LDAP 1.2.2 with Spring Core 2.5 and trying to implement a search of my AD-LDAP interface. The method that performs the lookup is in a LDAP bound Dao that uses the Spring ldapTemplate. The code is called via Ajax, on keys fired, to do an incremental lookup like the google suggestion box. The problem is much of the time, the filter throws a NullPointerException, and I can't figure out why.

    Here is the search code:
    Code:
    1  public List<Person> findByEmailSearch(String name) {
    2          List<Person> allPeople= new ArrayList<Person>();
    3          PagedResultsRequestControl control = new PagedResultsRequestControl(20);
    4          SearchControls searchControls = new SearchControls();
    5          searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    6          final int MAX_RESULT= 40;
    7          //String filter = "(mail=" + name + ")";
    8          EqualsFilter filter= new EqualsFilter("mail", name);
    9          while (true) {
    10                  try {
    11                          List persons= ldapTemplate.search(DistinguishedName.EMPTY_PATH, filter.encode(), searchControls, getContextMapper(), control);
    12                          PagedResultsCookie cookie = control.getCookie();
    13                          if(persons != null){
    14                                  allPeople.addAll(persons);
    15                          }
    16                          if(cookie == null){ // bail out of loop if cookie is null, end of the list
    17                                  break;
    18                          }
    19                          if(allPeople.size() >= MAX_RESULT){ // bail out of loop if we've reached max result.
    20                                  break;
    21                          }
    22                  } catch (Exception e) {
    23                          System.out.println("*** Exception "+ e.getLocalizedMessage() + " filter: " + filter + " Search Name: " + name);
    24                          break; 
    25                  }
    26          }
    27          return allPeople;
    28  }
    Line 23 prints: 16:22:43,987 INFO [STDOUT] *** Exception null filter: (mail=*de s*) Search Name: *de s* How can the exception message be a null filter and yet the filter prints a value. I suspect the problem is the space in name value passed in, I've also tried the WhitespaceWildcardsFilter with the same result.

    Any reply is appreciated.

    Thanks in advance!
    MG

  2. #2
    Join Date
    Jul 2005
    Location
    Helsingborg, Sweden
    Posts
    504

    Default

    It's your code that prints the message "Exception null filter: ...".

    Code:
    System.out.println("*** Exception "+ e.getLocalizedMessage() + " filter: " ...
    It has nothing to do with a null filter. You should print the whole stacktrace and not just the localized message (which often is null).
    Ulrik Sandberg
    Jayway (www.jayway.com)
    Spring LDAP project member

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •