Prevent against NPE inside ComponentKey

b/31063280

Change-Id: I71254fc1a3244fd6834ebf65923d194f17afc1ba
This commit is contained in:
Hyunyoung Song
2016-08-24 16:23:09 -07:00
parent 527c27c04e
commit ada6cbe4ef
2 changed files with 10 additions and 2 deletions
@@ -32,8 +32,8 @@ public class ComponentKey {
private final int mHashCode;
public ComponentKey(ComponentName componentName, UserHandleCompat user) {
assert (componentName != null);
assert (user != null);
Preconditions.assertNotNull(componentName);
Preconditions.assertNotNull(user);
this.componentName = componentName;
this.user = user;
mHashCode = Arrays.hashCode(new Object[] {componentName, user});
@@ -58,6 +58,8 @@ public class ComponentKey {
componentName = ComponentName.unflattenFromString(componentKeyStr);
user = UserHandleCompat.myUserHandle();
}
Preconditions.assertNotNull(componentName);
Preconditions.assertNotNull(user);
mHashCode = Arrays.hashCode(new Object[] {componentName, user});
}
@@ -26,6 +26,12 @@ import com.android.launcher3.config.ProviderConfig;
*/
public class Preconditions {
public static void assertNotNull(Object o) {
if (ProviderConfig.IS_DOGFOOD_BUILD && o == null) {
throw new IllegalStateException();
}
}
public static void assertWorkerThread() {
if (ProviderConfig.IS_DOGFOOD_BUILD && !isSameLooper(LauncherModel.getWorkerLooper())) {
throw new IllegalStateException();