From 452fb42f5f6f6b81f215caa819d14636aaec47cf Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 31 Mar 2010 14:27:38 -0700 Subject: ADT NPW: NPE when trying to expand project templates. This does not solve the NPE, it adds logging so that we can identify the issue since it doesn't happend in debug mode. Probably some template is not loaded correctly. SDK Bug: 2546962 Change-Id: Idf0df2bd4e4b7a632fc7777b296df830c2f642da --- .../wizards/newproject/NewProjectWizard.java | 40 +++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizard.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizard.java index 2d51f89..39be01c 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizard.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizard.java @@ -39,6 +39,7 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.SubProgressMonitor; @@ -513,6 +514,9 @@ public class NewProjectWizard extends Wizard implements INewWizard { try { getContainer().run(true /* fork */, true /* cancelable */, op); } catch (InvocationTargetException e) { + + AdtPlugin.log(e, "New Project Wizard failed"); + // The runnable threw an exception Throwable t = e.getTargetException(); if (t instanceof CoreException) { @@ -522,11 +526,20 @@ public class NewProjectWizard extends Wizard implements INewWizard { // and there's a resource with a similar name. MessageDialog.openError(getShell(), "Error", "Error: Case Variant Exists"); } else { - ErrorDialog.openError(getShell(), "Error", null, core.getStatus()); + ErrorDialog.openError(getShell(), "Error", core.getMessage(), core.getStatus()); } } else { // Some other kind of exception - MessageDialog.openError(getShell(), "Error", t.getMessage()); + String msg = t.getMessage(); + Throwable t1 = t; + while (msg == null && t1.getCause() != null) { + msg = t1.getMessage(); + t1 = t1.getCause(); + } + if (msg == null) { + msg = t.toString(); + } + MessageDialog.openError(getShell(), "Error", msg); } e.printStackTrace(); } catch (InterruptedException e) { @@ -1083,9 +1096,28 @@ public class NewProjectWizard extends Wizard implements INewWizard { * @return A new String object with the placeholder replaced by the values. */ private String replaceParameters(String str, Map parameters) { + + if (parameters == null) { + AdtPlugin.log(IStatus.ERROR, + "NPW replace parameters: null parameter map. String: '%s'", str); //$NON-NLS-1$ + return str; + } else if (str == null) { + AdtPlugin.log(IStatus.ERROR, + "NPW replace parameters: null template string"); //$NON-NLS-1$ + return str; + } + for (Entry entry : parameters.entrySet()) { - if (entry.getValue() instanceof String) { - str = str.replaceAll(entry.getKey(), (String) entry.getValue()); + if (entry != null && entry.getValue() instanceof String) { + Object value = entry.getValue(); + if (value == null) { + AdtPlugin.log(IStatus.ERROR, + "NPW replace parameters: null value for key '%s' in template '%s'", //$NON-NLS-1$ + entry.getKey(), + str); + } else { + str = str.replaceAll(entry.getKey(), (String) value); + } } } -- cgit v1.1