From c6031ab7c80b9bf8c19f3bced4797bb0bacae3f2 Mon Sep 17 00:00:00 2001 From: Koji Fukui Date: Mon, 1 Apr 2013 14:37:01 +0900 Subject: Avoid NullPointerException in getHandler() mAttachInfo may be set to null by other threads while running getHandler(). This fix assigns mAttachInfo to a local variable. Checking null pointer and getting a member variable are executed through the local variable. This local variable is constant. So NullPointerException doesn't occur even if mAttachInfo is set to null while running getHandler(). Change-Id: I4013dfb7951bd864628868ed58f8c4f5b7cbd1d3 --- core/java/android/view/View.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 0d2141f0071d..75b8e97a0945 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -10525,8 +10525,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * handler can be used to pump events in the UI events queue. */ public Handler getHandler() { - if (mAttachInfo != null) { - return mAttachInfo.mHandler; + final AttachInfo attachInfo = mAttachInfo; + if (attachInfo != null) { + return attachInfo.mHandler; } return null; } -- cgit v1.2.3-59-g8ed1b