AnsweredAssumed Answered

Bug on UserCache (need to trim the user names at some point)

Question asked by aparraga on Sep 3, 2012
Latest reply on Sep 18, 2012 by jbarrez
When the first or last name contains extra white spaces at the end / start, the code at TrieBasedUserCache fails in the addTrieItem method, since the getKeys returns empty keys.
e.g. if the user is fn: "Antonio "  ln: "Parraga", so the getKeys returns an array of 3 elements, ['Antonio', '', 'Parraga'], and the loop fails.
When this method fails, nobody catches the exception, so if the explorer has added 15 users and fails in the next user (the user number 16), it will believe that it has just 15 users, no matter if you have a million of users :)

I have fixed the method by adding 2 trims at this point, but we can do it in other places:


  protected String[] getKeys(User user) {
    String fullname = "";
    if (user.getFirstName() != null) {
      fullname += user.getFirstName().trim();
    }
    if (user.getLastName() != null) {
      fullname += " " + user.getLastName().trim();
    }
   
    return fullname.split(" ");
  }

please let me know if it makes sense to you. Thank you

Outcomes