From 8f124842dd16125062f048257889c85380879b68 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Wed, 30 Jan 2013 16:23:40 -0800 Subject: [PATCH] Avoid redundant store into array list. Prevent possible NPE in case of a race condition while fetching input devices by descriptor. Change-Id: I68d0738386c6723d943e595f829981b0890c2b3a --- core/java/android/hardware/input/InputManager.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/java/android/hardware/input/InputManager.java b/core/java/android/hardware/input/InputManager.java index 262d87d84818f..6b00c5829c147 100644 --- a/core/java/android/hardware/input/InputManager.java +++ b/core/java/android/hardware/input/InputManager.java @@ -212,8 +212,10 @@ public final class InputManager { } catch (RemoteException ex) { throw new RuntimeException("Could not get input device information.", ex); } + if (inputDevice != null) { + mInputDevices.setValueAt(index, inputDevice); + } } - mInputDevices.setValueAt(index, inputDevice); return inputDevice; } } @@ -241,6 +243,8 @@ public final class InputManager { inputDevice = mIm.getInputDevice(id); } catch (RemoteException ex) { // Ignore the problem for the purposes of this method. + } + if (inputDevice == null) { continue; } mInputDevices.setValueAt(i, inputDevice);