Bug 578158 fix NPE in BundleLauncherHelper.addPlugin
Change-Id: I7736554b74c7095e3b41eeb14b59cf5d72147e57
Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
Reviewed-on: https://git.eclipse.org/r/c/pde/eclipse.pde.ui/+/189471
Reviewed-by: Lars Vogel <Lars.Vogel@vogella.com>
Reviewed-by: Hannes Wellmann <wellmann.hannes1@gmx.net>
Tested-by: Lars Vogel <Lars.Vogel@vogella.com>
diff --git a/ui/org.eclipse.pde.launching/src/org/eclipse/pde/internal/launching/launcher/BundleLauncherHelper.java b/ui/org.eclipse.pde.launching/src/org/eclipse/pde/internal/launching/launcher/BundleLauncherHelper.java
index f2491cf..355ebd9 100644
--- a/ui/org.eclipse.pde.launching/src/org/eclipse/pde/internal/launching/launcher/BundleLauncherHelper.java
+++ b/ui/org.eclipse.pde.launching/src/org/eclipse/pde/internal/launching/launcher/BundleLauncherHelper.java
@@ -364,7 +364,7 @@
return map;
}
- static final Comparator<IPluginModelBase> VERSION = Comparator.comparing(m -> m.getBundleDescription().getVersion());
+ static final Comparator<IPluginModelBase> VERSION = Comparator.comparing(BundleLauncherHelper::getVersion);
private static Iterable<IPluginModelBase> getSelectedModels(IPluginModelBase[] models, String version, boolean greedy) {
// match only if...
@@ -388,7 +388,7 @@
addBundleToMap(map, model, startData);
} else {
List<Version> pluginVersions = idVersions.computeIfAbsent(model.getPluginBase().getId(), n -> new ArrayList<>());
- Version version = model.getBundleDescription().getVersion();
+ Version version = getVersion(model);
if (!containsVersion.test(pluginVersions, version)) { // apply version filter
pluginVersions.add(version);
addBundleToMap(map, model, startData);
@@ -396,6 +396,21 @@
}
}
+ private static Version getVersion(IPluginModelBase model) {
+ BundleDescription bundleDescription = model.getBundleDescription();
+ Version version;
+ if (bundleDescription == null) {
+ try {
+ version = Version.parseVersion(model.getPluginBase().getVersion());
+ } catch (IllegalArgumentException e) {
+ return Version.emptyVersion;
+ }
+ } else {
+ version = bundleDescription.getVersion();
+ }
+ return version;
+ }
+
/**
* Adds the given bundle and start information to the map. This will override anything set
* for system bundles, and set their start level to the appropriate level
@@ -510,7 +525,7 @@
value = value.replace(':', ',');
}
value = (value.length() == 0 || value.equals(",")) //$NON-NLS-1$
- ? null
+ ? null
: value.substring(0, value.length() - 1);
boolean automatic = configuration.getAttribute(IPDELauncherConstants.AUTOMATIC_ADD, true);