Fix NPE that prevented any package w/o license to be installed.

java.util.Properties#setProperty() doesn't like it when the value is null
which was the case when a package had no license.

Made sure it won't happen on other properties than the license as well.

Also improved error display when an unexpected Throwable is thrown during
install (Stack Call is now display if the Throwable has no message).

BUG:2037085
This commit is contained in:
Xavier Ducrohet
2009-08-05 17:09:35 -07:00
parent 03fe616acb
commit 6d673960b0
4 changed files with 34 additions and 7 deletions

View File

@@ -126,8 +126,12 @@ public class AddonPackage extends Package {
super.saveProperties(props); super.saveProperties(props);
mVersion.saveProperties(props); mVersion.saveProperties(props);
props.setProperty(PROP_NAME, mName); if (mName != null) {
props.setProperty(PROP_VENDOR, mVendor); props.setProperty(PROP_NAME, mName);
}
if (mVendor != null) {
props.setProperty(PROP_VENDOR, mVendor);
}
} }
/** /**

View File

@@ -145,9 +145,15 @@ public abstract class Package implements IDescription {
*/ */
void saveProperties(Properties props) { void saveProperties(Properties props) {
props.setProperty(PROP_REVISION, Integer.toString(mRevision)); props.setProperty(PROP_REVISION, Integer.toString(mRevision));
props.setProperty(PROP_LICENSE, mLicense); if (mLicense != null) {
props.setProperty(PROP_DESC, mDescription); props.setProperty(PROP_LICENSE, mLicense);
props.setProperty(PROP_DESC_URL, mDescUrl); }
if (mDescription != null) {
props.setProperty(PROP_DESC, mDescription);
}
if (mDescUrl != null) {
props.setProperty(PROP_DESC_URL, mDescUrl);
}
if (mSource != null) { if (mSource != null) {
props.setProperty(PROP_SOURCE_URL, mSource.getUrl()); props.setProperty(PROP_SOURCE_URL, mSource.getUrl());

View File

@@ -87,7 +87,9 @@ public class PlatformPackage extends Package {
super.saveProperties(props); super.saveProperties(props);
mVersion.saveProperties(props); mVersion.saveProperties(props);
props.setProperty(PROP_VERSION, mVersionName); if (mVersionName != null) {
props.setProperty(PROP_VERSION, mVersionName);
}
} }
/** Returns the version, a string, for platform packages. */ /** Returns the version, a string, for platform packages. */

View File

@@ -36,6 +36,8 @@ import com.android.sdkuilib.repository.UpdaterWindow.ISdkListener;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@@ -304,8 +306,21 @@ class UpdaterData {
} catch (Throwable t) { } catch (Throwable t) {
// Display anything unexpected in the monitor. // Display anything unexpected in the monitor.
monitor.setResult("Unexpected Error: %1$s", t.getMessage()); String msg = t.getMessage();
if (msg != null) {
monitor.setResult("Unexpected Error installing '%1%s: %2$s",
archive.getParentPackage().getShortDescription(), msg);
} else {
// no error info? get the stack call to display it
// At least that'll give us a better bug report.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
t.printStackTrace(new PrintStream(baos));
// and display it
monitor.setResult("Unexpected Error installing '%1$s\n%2$s",
archive.getParentPackage().getShortDescription(),
baos.toString());
}
} finally { } finally {
// Always move the progress bar to the desired position. // Always move the progress bar to the desired position.