aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSiva Velusamy <vsiva@google.com>2014-07-01 09:07:02 -0700
committerSiva Velusamy <vsiva@google.com>2014-07-01 10:21:39 -0700
commite37856e9fcdffb530ceb5182d5b17fb4076b5df3 (patch)
tree38aa7fe73a69a47d846c18260861a2f26f44f41a
parent38f216ff09e2546b61e5978e75e50811ff450644 (diff)
downloadsdk-e37856e9fcdffb530ceb5182d5b17fb4076b5df3.zip
sdk-e37856e9fcdffb530ceb5182d5b17fb4076b5df3.tar.gz
sdk-e37856e9fcdffb530ceb5182d5b17fb4076b5df3.tar.bz2
ADT: Fix NPE in InstrumentationRunnerValidator
This CL adds a few checks to guard against NPEs that could occur if the manifest parsing failed (e.g. due to a missing manifest) Change-Id: I82a9b3b1fa3d651c13125798f70b61e5492e0838
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/junit/AndroidJUnitLaunchConfigurationTab.java21
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/junit/InstrumentationRunnerValidator.java13
2 files changed, 21 insertions, 13 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/junit/AndroidJUnitLaunchConfigurationTab.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/junit/AndroidJUnitLaunchConfigurationTab.java
index 4f02fa9..038f0b9 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/junit/AndroidJUnitLaunchConfigurationTab.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/junit/AndroidJUnitLaunchConfigurationTab.java
@@ -1017,18 +1017,17 @@ public class AndroidJUnitLaunchConfigurationTab extends AbstractLaunchConfigurat
*/
private void loadInstrumentations(IProject project) {
try {
- mInstrValidator = new InstrumentationRunnerValidator(project);
- mInstrumentations = (mInstrValidator == null ? null :
- mInstrValidator.getInstrumentationNames());
- if (mInstrumentations != null) {
- mInstrumentationCombo.removeAll();
- for (String instrumentation : mInstrumentations) {
- mInstrumentationCombo.add(instrumentation);
+ mInstrValidator = new InstrumentationRunnerValidator(project);
+ mInstrumentations = mInstrValidator.getInstrumentationNames();
+ if (mInstrumentations.length > 0) {
+ mInstrumentationCombo.removeAll();
+ for (String instrumentation : mInstrumentations) {
+ mInstrumentationCombo.add(instrumentation);
+ }
+ // the selection will be set when we update the ui from the current
+ // config object.
+ return;
}
- // the selection will be set when we update the ui from the current
- // config object.
- return;
- }
} catch (CoreException e) {
AdtPlugin.logAndPrintError(e, project.getName(),
LaunchMessages.AndroidJUnitTab_LoadInstrError_s,
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/junit/InstrumentationRunnerValidator.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/junit/InstrumentationRunnerValidator.java
index 54fd207..820fed7 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/junit/InstrumentationRunnerValidator.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/junit/InstrumentationRunnerValidator.java
@@ -16,6 +16,8 @@
package com.android.ide.eclipse.adt.internal.launch.junit;
import com.android.SdkConstants;
+import com.android.annotations.NonNull;
+import com.android.annotations.Nullable;
import com.android.ide.common.xml.ManifestData;
import com.android.ide.common.xml.ManifestData.Instrumentation;
import com.android.ide.common.xml.ManifestData.UsesLibrary;
@@ -71,6 +73,12 @@ class InstrumentationRunnerValidator {
}
private void init(ManifestData manifestData) {
+ if (manifestData == null) {
+ mInstrumentationNames = new String[0];
+ mHasRunnerLibrary = false;
+ return;
+ }
+
Instrumentation[] instrumentations = manifestData.getInstrumentations();
mInstrumentationNames = new String[instrumentations.length];
for (int i = 0; i < instrumentations.length; i++) {
@@ -98,9 +106,9 @@ class InstrumentationRunnerValidator {
/**
* Return the set of instrumentation names for the Android project.
*
- * @return <code>null</code> if error occurred parsing instrumentations, otherwise returns array
- * of instrumentation class names
+ * @return array of instrumentation class names, possibly empty
*/
+ @NonNull
String[] getInstrumentationNames() {
return mInstrumentationNames;
}
@@ -111,6 +119,7 @@ class InstrumentationRunnerValidator {
* @return fully qualified instrumentation class name. <code>null</code> if no valid
* instrumentation can be found.
*/
+ @Nullable
String getValidInstrumentationTestRunner() {
for (String instrumentation : getInstrumentationNames()) {
if (validateInstrumentationRunner(instrumentation) == INSTRUMENTATION_OK) {