From 06f938e8aa56cd89ab0bdb04c8b946392c428dd1 Mon Sep 17 00:00:00 2001 From: Svetoslav Ganov Date: Thu, 10 Nov 2011 14:31:37 -0800 Subject: [PATCH] PopupWindow dismiss() can get into a recursive loop. 1. The dismiss method in a PopupWindow is first removing the popup View from the WindowManager and then if the content View differs from the popup View the former is removed from the latter. Then dismiss() clears the dismissed flag so a subsequent call to dismiss() is a NOP. However, removing a View both from the WindowManager and from its parent ViewGroup triggers stuff wich may lead to a subsequent call to dismiss(). This leads to a stack overflow exception. bug:5598944 Change-Id: I2aeeda591be3e9aa98fec1ee17ea8f0e746e6992 --- core/java/android/widget/PopupWindow.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java index 8ba7beed3ffd7..5fa4ad09655f2 100644 --- a/core/java/android/widget/PopupWindow.java +++ b/core/java/android/widget/PopupWindow.java @@ -1248,6 +1248,8 @@ public class PopupWindow { */ public void dismiss() { if (isShowing() && mPopupView != null) { + mIsShowing = false; + unregisterForScrollChanged(); try { @@ -1257,7 +1259,6 @@ public class PopupWindow { ((ViewGroup) mPopupView).removeView(mContentView); } mPopupView = null; - mIsShowing = false; if (mOnDismissListener != null) { mOnDismissListener.onDismiss();