From acdfbcca6f91bdf3f77ed7b2e699c97ce98c1fb8 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Tue, 19 Jun 2012 15:07:05 -0700 Subject: Fix issue #6675499: java.lang.RuntimeException: Unable to start... ...activity ComponentInfo{com.google.android.gm/ com.google.android.gm.ui.MailActivityGmail}: java.lang.NullPointerException There were a number of places in FragmentManagerImpl where we were not dealing with mAdded being null. In the original implementation, mAdded would almost always be null if mActive is null. As we have added features, this has become a less strong guarantee (and it actually was never completely guaranteed), but there are a lot of places where we would check for mActive being non-null and assume this meant mAdded is non-null. Fix these to correctly check for mAdded. Bug: 6675499 Change-Id: I2a6a801d8bc89550fc73e12c9c3f8bb0ad6c7fa4 --- core/java/android/app/FragmentManager.java | 35 ++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'core/java/android/app/FragmentManager.java') diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java index 9ba5305..39e2423 100644 --- a/core/java/android/app/FragmentManager.java +++ b/core/java/android/app/FragmentManager.java @@ -1118,7 +1118,9 @@ final class FragmentManagerImpl extends FragmentManager { if (DEBUG) Log.v(TAG, "remove: " + fragment + " nesting=" + fragment.mBackStackNesting); final boolean inactive = !fragment.isInBackStack(); if (!fragment.mDetached || inactive) { - mAdded.remove(fragment); + if (mAdded != null) { + mAdded.remove(fragment); + } if (fragment.mHasMenu && fragment.mMenuVisible) { mNeedMenuInvalidate = true; } @@ -1187,7 +1189,9 @@ final class FragmentManagerImpl extends FragmentManager { fragment.mDetached = true; if (fragment.mAdded) { // We are not already in back stack, so need to remove the fragment. - mAdded.remove(fragment); + if (mAdded != null) { + mAdded.remove(fragment); + } if (fragment.mHasMenu && fragment.mMenuVisible) { mNeedMenuInvalidate = true; } @@ -1202,6 +1206,9 @@ final class FragmentManagerImpl extends FragmentManager { if (fragment.mDetached) { fragment.mDetached = false; if (!fragment.mAdded) { + if (mAdded == null) { + mAdded = new ArrayList(); + } mAdded.add(fragment); fragment.mAdded = true; if (fragment.mHasMenu && fragment.mMenuVisible) { @@ -1213,7 +1220,7 @@ final class FragmentManagerImpl extends FragmentManager { } public Fragment findFragmentById(int id) { - if (mActive != null) { + if (mAdded != null) { // First look through added fragments. for (int i=mAdded.size()-1; i>=0; i--) { Fragment f = mAdded.get(i); @@ -1221,6 +1228,8 @@ final class FragmentManagerImpl extends FragmentManager { return f; } } + } + if (mActive != null) { // Now for any known fragment. for (int i=mActive.size()-1; i>=0; i--) { Fragment f = mActive.get(i); @@ -1233,7 +1242,7 @@ final class FragmentManagerImpl extends FragmentManager { } public Fragment findFragmentByTag(String tag) { - if (mActive != null && tag != null) { + if (mAdded != null && tag != null) { // First look through added fragments. for (int i=mAdded.size()-1; i>=0; i--) { Fragment f = mAdded.get(i); @@ -1241,6 +1250,8 @@ final class FragmentManagerImpl extends FragmentManager { return f; } } + } + if (mActive != null && tag != null) { // Now for any known fragment. for (int i=mActive.size()-1; i>=0; i--) { Fragment f = mActive.get(i); @@ -1817,7 +1828,7 @@ final class FragmentManagerImpl extends FragmentManager { } public void dispatchConfigurationChanged(Configuration newConfig) { - if (mActive != null) { + if (mAdded != null) { for (int i=0; i newMenus = null; - if (mActive != null) { + if (mAdded != null) { for (int i=0; i