From a6dc10887d24122fa8a9d8b590ac7eff2c36724c Mon Sep 17 00:00:00 2001 From: Siva Velusamy Date: Mon, 10 Oct 2011 10:48:34 -0700 Subject: [PATCH] Fix NPE when getCurrentDevice() == null. Change-Id: I0f9eaf599b5ab22487408ea74d597ea61a22793f --- .../src/com/android/ddmuilib/logcat/LogCatPanel.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java index b34b756f7..35cef9634 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java @@ -17,6 +17,8 @@ package com.android.ddmuilib.logcat; import com.android.ddmlib.DdmConstants; +import com.android.ddmlib.IDevice; +import com.android.ddmlib.Log; import com.android.ddmlib.Log.LogLevel; import com.android.ddmuilib.ITableFocusListener; import com.android.ddmuilib.ImageLoader; @@ -122,6 +124,8 @@ public final class LogCatPanel extends SelectionDependentPanel private static final int[] WEIGHTS_SHOW_FILTERS = new int[] {15, 85}; private static final int[] WEIGHTS_LOGCAT_ONLY = new int[] {0, 100}; + private static final String LOG_TAG = "LogCatPanel"; + private LogCatReceiver mReceiver; private IPreferenceStore mPrefStore; @@ -215,6 +219,14 @@ public final class LogCatPanel extends SelectionDependentPanel @Override public void deviceSelected() { + IDevice device = getCurrentDevice(); + if (device == null) { + // If the device is not working properly, getCurrentDevice() could return null. + // In such a case, we don't launch logcat, nor switch the display. + Log.e(LOG_TAG, "Device selected, but getCurrentDevice() == null"); + return; + } + if (mReceiver != null) { // Don't need to listen to new logcat messages from previous device anymore. mReceiver.removeMessageReceivedEventListener(this); @@ -225,7 +237,7 @@ public final class LogCatPanel extends SelectionDependentPanel } } - mReceiver = LogCatReceiverFactory.INSTANCE.newReceiver(getCurrentDevice(), mPrefStore); + mReceiver = LogCatReceiverFactory.INSTANCE.newReceiver(device, mPrefStore); mReceiver.addMessageReceivedEventListener(this); mViewer.setInput(mReceiver.getMessages()); -- 2.11.0