From faebce1cc09653321a12b8472fd02b79dad95c58 Mon Sep 17 00:00:00 2001 From: Raphael Moll Date: Sat, 2 Jun 2012 14:54:18 -0700 Subject: ADT: NPE when capturing emulator output. This can happen when starting an emulator from the AVD selector (or the AVD Manager window.) Change-Id: I6f5098bddc0fa54d89c164e98c51cd80509bbaf7 --- .../sdkuilib/internal/widgets/AvdSelector.java | 28 +++++++++++++--------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'sdkmanager/libs/sdkuilib') diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdSelector.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdSelector.java index 72488a3..3a76b2a 100644 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdSelector.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdSelector.java @@ -1091,7 +1091,7 @@ public final class AvdSelector { final ProgressTask progress = new ProgressTask(mTable.getShell(), "Starting Android Emulator"); progress.start(new ITask() { - ITaskMonitor mMonitor = null; + volatile ITaskMonitor mMonitor = null; @Override public void run(final ITaskMonitor monitor) { @@ -1115,16 +1115,12 @@ public final class AvdSelector { new IProcessOutput() { @Override public void out(@Nullable String line) { - if (line != null) { - filterStdOut(line); - } + filterStdOut(line); } @Override public void err(@Nullable String line) { - if (line != null) { - filterStdErr(line); - } + filterStdErr(line); } }); @@ -1150,6 +1146,11 @@ public final class AvdSelector { } private void filterStdOut(String line) { + ITaskMonitor m = mMonitor; + if (line == null || m == null) { + return; + } + // Skip some non-useful messages. if (line.indexOf("NSQuickDrawView") != -1) { //$NON-NLS-1$ // Discard the MacOS warning: @@ -1162,22 +1163,27 @@ public final class AvdSelector { if (line.toLowerCase().indexOf("error") != -1 || //$NON-NLS-1$ line.indexOf("qemu: fatal") != -1) { //$NON-NLS-1$ // Sometimes the emulator seems to output errors on stdout. Catch these. - mMonitor.logError("%1$s", line); //$NON-NLS-1$ + m.logError("%1$s", line); //$NON-NLS-1$ return; } - mMonitor.log("%1$s", line); //$NON-NLS-1$ + m.log("%1$s", line); //$NON-NLS-1$ } private void filterStdErr(String line) { + ITaskMonitor m = mMonitor; + if (line == null || m == null) { + return; + } + if (line.indexOf("emulator: device") != -1 || //$NON-NLS-1$ line.indexOf("HAX is working") != -1) { //$NON-NLS-1$ // These are not errors. Output them as regular stdout messages. - mMonitor.log("%1$s", line); //$NON-NLS-1$ + m.log("%1$s", line); //$NON-NLS-1$ return; } - mMonitor.logError("%1$s", line); //$NON-NLS-1$ + m.logError("%1$s", line); //$NON-NLS-1$ } }); } -- cgit v1.1