OSDN Git Service

Fix NPE when combining pop with add transaction.
authorGeorge Mount <mount@google.com>
Wed, 1 Mar 2017 23:38:02 +0000 (15:38 -0800)
committerGeorge Mount <mount@google.com>
Thu, 2 Mar 2017 00:51:21 +0000 (16:51 -0800)
Bug 35832085

When pop transactions and an add transaction are acting
in the same frame, optimized tranactions can work properly,
but unoptimized transactions have no guarantees. This fixes
a crash with unoptimized transactions so they will at least
not break.

Test: I996f54ae2540f31134e6a9a28870826a73ea1610
Change-Id: I3890dd30e9aff70f4ac142773de8479f1a9dffc8

core/java/android/app/FragmentTransition.java

index f62ab8d..780a922 100644 (file)
@@ -780,8 +780,10 @@ class FragmentTransition {
             names = inTransaction.mSharedElementTargetNames;
         }
 
-        inSharedElements.retainAll(names);
-        if (sharedElementCallback != null) {
+        if (names != null) {
+            inSharedElements.retainAll(names);
+        }
+        if (names != null && sharedElementCallback != null) {
             sharedElementCallback.onMapSharedElements(names, inSharedElements);
             for (int i = names.size() - 1; i >= 0; i--) {
                 String name = names.get(i);
@@ -830,8 +832,9 @@ class FragmentTransition {
             FragmentContainerTransition fragments,
             Transition enterTransition, boolean inIsPop) {
         BackStackRecord inTransaction = fragments.lastInTransaction;
-        if (enterTransition != null && inTransaction.mSharedElementSourceNames != null &&
-                !inTransaction.mSharedElementSourceNames.isEmpty()) {
+        if (enterTransition != null && inSharedElements != null
+                && inTransaction.mSharedElementSourceNames != null
+                && !inTransaction.mSharedElementSourceNames.isEmpty()) {
             final String targetName = inIsPop
                     ? inTransaction.mSharedElementSourceNames.get(0)
                     : inTransaction.mSharedElementTargetNames.get(0);
@@ -1096,7 +1099,9 @@ class FragmentTransition {
         if (transition != null) {
             viewList = new ArrayList<>();
             View root = fragment.getView();
-            root.captureTransitioningViews(viewList);
+            if (root != null) {
+                root.captureTransitioningViews(viewList);
+            }
             if (sharedElements != null) {
                 viewList.removeAll(sharedElements);
             }