cancel
Showing results for 
Search instead for 
Did you mean: 

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

aparraga
Champ in-the-making
Champ in-the-making
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 Smiley Happy

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
1 REPLY 1

jbarrez
Star Contributor
Star Contributor
I'm wondering: is there any use case for users with whitspace at the beginning/end of their name?