OSDN Git Service

Provide synchronization to setview to avoid NPE
authorGopal Krishna Shukla <gshukla@codeaurora.org>
Wed, 6 Jul 2016 02:44:59 +0000 (08:14 +0530)
committerShibin George <shibing@codeaurora.org>
Thu, 22 Sep 2016 04:48:24 +0000 (04:48 +0000)
If setView() will be called from two different threads
then mView property of a View object may have inconsistent
value. For instance, setView() may set mView to null causing
NullPointerException. Synchronize root.setView() as well to
avoid this.

Change-Id: I5f9cf47ece5d4aca575bd8644ecfcee0ed43d843

core/java/android/view/WindowManagerGlobal.java

index 11734d3..830df99 100644 (file)
@@ -335,20 +335,17 @@ public final class WindowManagerGlobal {
             mViews.add(view);
             mRoots.add(root);
             mParams.add(wparams);
-        }
 
-        // do this last because it fires off messages to start doing things
-        try {
-            root.setView(view, wparams, panelParentView);
-        } catch (RuntimeException e) {
-            // BadTokenException or InvalidDisplayException, clean up.
-            synchronized (mLock) {
-                final int index = findViewLocked(view, false);
+            // do this last because it fires off messages to start doing things
+            try {
+                root.setView(view, wparams, panelParentView);
+            } catch (RuntimeException e) {
+                // BadTokenException or InvalidDisplayException, clean up.
                 if (index >= 0) {
                     removeViewLocked(index, true);
                 }
+                throw e;
             }
-            throw e;
         }
     }