[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [orbot/master] handle NPE on number format instance



commit 1bc427b50e91c30bdb0f75a2b31f9f8c7f9c6403
Author: Nathan Freitas <nathan@xxxxxxxxxxx>
Date:   Mon Apr 13 10:25:58 2015 -0400

    handle NPE on number format instance
---
 src/org/torproject/android/service/TorService.java |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
index 1a48c46..50792b8 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -604,6 +604,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
     {
         try
         {
+            mNumberFormat = NumberFormat.getInstance(Locale.getDefault()); //localized numbers!
 
             if (mNotificationManager == null)
             {
@@ -636,7 +637,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
                 }
             }).start();
         
-            mNumberFormat = NumberFormat.getInstance(Locale.getDefault()); //localized numbers!
             
             if (OrbotVpnService.mSocksProxyPort == -1)
             	OrbotVpnService.mSocksProxyPort = (int)((Math.random()*1000)+10000); 
@@ -1619,10 +1619,13 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
         // Converts the supplied argument into a string.
         // Under 2Mb, returns "xxx.xKb"
         // Over 2Mb, returns "xxx.xxMb"
-        if (count < 1e6)
-            return mNumberFormat.format(Math.round((float)((int)(count*10/1024))/10)) + "Kbps";
-        else
-        	return mNumberFormat.format(Math.round((float)((int)(count*100/1024/1024))/100)) + "Mbps";
+ 	if (mNumberFormat != null)
+        	if (count < 1e6)
+            		return mNumberFormat.format(Math.round((float)((int)(count*10/1024))/10)) + "Kbps";
+        	else
+            		return mNumberFormat.format(Math.round((float)((int)(count*100/1024/1024))/100)) + "Mbps";
+	else
+		return "";
         
            //return count+" kB";
     }



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits