Bug 940575 - Handle null background thread in isOnBackgroundThread() (r=rnewman)
authorLucas Rocha <lucasr@mozilla.com>
Tue, 01 Apr 2014 15:02:13 +0100
changeset 194920 b13253fea34208b7233dbc84f16352fe535b0052
parent 194919 c8d89b74315861c31da43d66aaa0b984e847b2cb
child 194921 0140e7b8fa0d03ecba48bfa742e2ece08b04553c
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs940575
milestone31.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 940575 - Handle null background thread in isOnBackgroundThread() (r=rnewman)
mobile/android/base/util/ThreadUtils.java
--- a/mobile/android/base/util/ThreadUtils.java
+++ b/mobile/android/base/util/ThreadUtils.java
@@ -18,18 +18,18 @@ public final class ThreadUtils {
      * Controls the action taken when a method like
      * {@link ThreadUtils#assertOnUiThread(AssertBehavior)} detects a problem.
      */
     public static enum AssertBehavior {
         NONE,
         THROW,
     }
 
-    private static Thread sUiThread;
-    private static Thread sBackgroundThread;
+    private static volatile Thread sUiThread;
+    private static volatile Thread sBackgroundThread;
 
     private static Handler sUiHandler;
 
     // Referenced directly from GeckoAppShell in highly performance-sensitive code (The extra
     // function call of the getter was harming performance. (Bug 897123))
     // Once Bug 709230 is resolved we should reconsider this as ProGuard should be able to optimise
     // this out at compile time.
     public static Handler sGeckoHandler;
@@ -153,16 +153,20 @@ public final class ThreadUtils {
         }
     }
 
     public static boolean isOnUiThread() {
         return isOnThread(getUiThread());
     }
 
     public static boolean isOnBackgroundThread() {
+        if (sBackgroundThread == null) {
+            return false;
+        }
+
         return isOnThread(sBackgroundThread);
     }
 
     public static boolean isOnThread(Thread thread) {
         return (Thread.currentThread().getId() == thread.getId());
     }
 
     /**