From 0e5ff9bdac9b79e4c31a4fb0233d660aaffd05de Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Fri, 30 Nov 2012 19:48:48 -0800 Subject: [PATCH] Fix for occasional NPE --- .../securesms/recipients/RecipientFactory.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/org/thoughtcrime/securesms/recipients/RecipientFactory.java b/src/org/thoughtcrime/securesms/recipients/RecipientFactory.java index 78a96a96f1..b0616c34cf 100644 --- a/src/org/thoughtcrime/securesms/recipients/RecipientFactory.java +++ b/src/org/thoughtcrime/securesms/recipients/RecipientFactory.java @@ -25,10 +25,11 @@ import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.util.NumberUtil; -import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.StringTokenizer; @@ -54,8 +55,11 @@ public class RecipientFactory { } public static Recipients getRecipientsForIds(Context context, String recipientIds) { - ArrayList results = new ArrayList(); - StringTokenizer tokenizer = new StringTokenizer(recipientIds.trim(), " "); + if (recipientIds == null || recipientIds.trim().length() == 0) + return new Recipients(new LinkedList()); + + List results = new LinkedList(); + StringTokenizer tokenizer = new StringTokenizer(recipientIds.trim(), " "); while (tokenizer.hasMoreTokens()) { String recipientId = tokenizer.nextToken(); @@ -87,8 +91,8 @@ public class RecipientFactory { } public static Recipients getRecipientsFromString(Context context, String rawText) throws RecipientFormattingException { - ArrayList results = new ArrayList(); - StringTokenizer tokenizer = new StringTokenizer(rawText, ","); + List results = new LinkedList(); + StringTokenizer tokenizer = new StringTokenizer(rawText, ","); while (tokenizer.hasMoreTokens()) { Recipient recipient = parseRecipient(context, tokenizer.nextToken());