From da2682ef9fed8115aa2ad5a7e8f306bb6a2d3c6f Mon Sep 17 00:00:00 2001 From: Marcos Marado Date: Tue, 18 Oct 2016 18:05:24 +0100 Subject: PhoneNumberHelper: formatNumber: check if isEmpty If formatNumber is invoked with an empty number, then there's no formatting to be done. This patch avoids an NPE while trying to parse an inexistent string. Change-Id: Ic7a9dd3d1e0e7b27457f59f1209387b7faa359d9 --- src/com/android/contacts/common/util/PhoneNumberHelper.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/com/android/contacts/common/util/PhoneNumberHelper.java b/src/com/android/contacts/common/util/PhoneNumberHelper.java index 39f8a39b..3c057052 100644 --- a/src/com/android/contacts/common/util/PhoneNumberHelper.java +++ b/src/com/android/contacts/common/util/PhoneNumberHelper.java @@ -118,8 +118,10 @@ public class PhoneNumberHelper { * is made public. */ public static String formatNumber(String phoneNumber, String defaultCountryIso) { - // Do not attempt to format numbers that start with a hash or star symbol. - if (phoneNumber.startsWith("#") || phoneNumber.startsWith("*")) { + // Do not attempt to format numbers that are empty or start with a hash + // or star symbol. + if (TextUtils.isEmpty(phoneNumber) || phoneNumber.startsWith("#") || + phoneNumber.startsWith("*")) { return phoneNumber; } -- cgit v1.2.3