From ac7b42776fb6d479ea001b2c1392188c0fa80551 Mon Sep 17 00:00:00 2001 From: Siva Velusamy Date: Fri, 22 Jun 2012 13:42:20 -0700 Subject: logcat: fix potential NPE Fix NPE that could happen if the device goes offline even before logcat command is issued on it, Change-Id: I334caae5e42d25eff396ce0b7b7a5e44c3ed4f61 --- .../ddmuilib/src/com/android/ddmuilib/logcat/LogCatReceiver.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'ddms') diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatReceiver.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatReceiver.java index 2674e92..da3e86f 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatReceiver.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatReceiver.java @@ -19,8 +19,8 @@ package com.android.ddmuilib.logcat; import com.android.ddmlib.IDevice; import com.android.ddmlib.IShellOutputReceiver; import com.android.ddmlib.Log; -import com.android.ddmlib.MultiLineReceiver; import com.android.ddmlib.Log.LogLevel; +import com.android.ddmlib.MultiLineReceiver; import org.eclipse.jface.preference.IPreferenceStore; @@ -97,7 +97,7 @@ public final class LogCatReceiver { @Override public void run() { /* wait while the device comes online */ - while (!mCurrentDevice.isOnline()) { + while (mCurrentDevice != null && !mCurrentDevice.isOnline()) { try { Thread.sleep(DEVICE_POLL_INTERVAL_MSEC); } catch (InterruptedException e) { @@ -106,8 +106,10 @@ public final class LogCatReceiver { } try { - mCurrentDevice.executeShellCommand(LOGCAT_COMMAND, + if (mCurrentDevice != null) { + mCurrentDevice.executeShellCommand(LOGCAT_COMMAND, mCurrentLogCatOutputReceiver, 0); + } } catch (Exception e) { /* There are 4 possible exceptions: TimeoutException, * AdbCommandRejectedException, ShellCommandUnresponsiveException and -- cgit v1.1