diff options
| author | Andrew Johnson | 2022-02-22 17:43:30 +0000 |
|---|---|---|
| committer | Andrew Johnson | 2022-02-22 17:43:30 +0000 |
| commit | d7025926fb6a5e282d964d787408142c7bb3b92b (patch) | |
| tree | c9ad1e8dc163f7dce229e76990605aa196e0f344 | |
| parent | d464a6161ad7d33258f869f6f44887b29d2a6157 (diff) | |
| download | org.eclipse.mat-d7025926fb6a5e282d964d787408142c7bb3b92b.tar.gz org.eclipse.mat-d7025926fb6a5e282d964d787408142c7bb3b92b.tar.xz org.eclipse.mat-d7025926fb6a5e282d964d787408142c7bb3b92b.zip | |
Bug 578912 Null pointer exception running Eclipse bundle explorer
On Eclipse 2021-12
Cope with different implementations of a list holding
capabilities of fragments.
Change-Id: I3d046b64068ca8e4645b770f63704507bebd0556
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=578912
| -rw-r--r-- | plugins/org.eclipse.mat.api/src/org/eclipse/mat/inspections/osgi/model/EquinoxBundleReader2.java | 61 |
1 files changed, 45 insertions, 16 deletions
diff --git a/plugins/org.eclipse.mat.api/src/org/eclipse/mat/inspections/osgi/model/EquinoxBundleReader2.java b/plugins/org.eclipse.mat.api/src/org/eclipse/mat/inspections/osgi/model/EquinoxBundleReader2.java index 6f1cb946..763e370c 100644 --- a/plugins/org.eclipse.mat.api/src/org/eclipse/mat/inspections/osgi/model/EquinoxBundleReader2.java +++ b/plugins/org.eclipse.mat.api/src/org/eclipse/mat/inspections/osgi/model/EquinoxBundleReader2.java @@ -1,5 +1,5 @@ /*******************************************************************************
- * Copyright (c) 2008, 2021 SAP AG, IBM Corporation and others
+ * Copyright (c) 2008, 2022 SAP AG, IBM Corporation and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -150,6 +150,32 @@ public class EquinoxBundleReader2 implements IBundleReader return bundleDescriptors;
}
+ /**
+ * Find the capabilities for a bundle.
+ * Copes with <= 2021-03, using regular collection,
+ * or >= 2021-06 using org.eclipse.osgi.internal.container.NamespaceList
+ * @param rev
+ * @return a collection extractor
+ * @throws SnapshotException
+ */
+ private ExtractedCollection getCapabilities(IObject rev) throws SnapshotException
+ {
+ ExtractedCollection extractedList = null;
+ IObject caps = (IObject) rev.resolveValue("capabilities");//$NON-NLS-1$
+ if (caps == null)
+ return null;
+ extractedList = CollectionExtractionUtils.extractList(caps);
+ if (extractedList == null)
+ {
+ // Try Eclipse 2021-06 using org.eclipse.osgi.internal.container.NamespaceList
+ caps = (IObject)caps.resolveValue("elements"); //$NON-NLS-1$
+ if (caps == null)
+ return null;
+ extractedList = CollectionExtractionUtils.extractList(caps);
+ }
+ return extractedList;
+ }
+
private boolean isFragment(IObject bundleHostObject) throws SnapshotException
{
IObject revs = (IObject) bundleHostObject.resolveValue("module.revisions.revisions");//$NON-NLS-1$
@@ -159,10 +185,10 @@ public class EquinoxBundleReader2 implements IBundleReader if (!it1.hasNext())
return false;
IObject rev = it1.next();
- IObject caps = (IObject) rev.resolveValue("capabilities");//$NON-NLS-1$
- if (caps == null)
+ ExtractedCollection extractedList = getCapabilities(rev);
+ if (extractedList == null)
return false;
- for (IObject o : CollectionExtractionUtils.extractList(caps))
+ for (IObject o : extractedList)
{
if ("equinox.fragment".equals(((IObject)(o.resolveValue("namespace"))).getClassSpecificName()))//$NON-NLS-1$ //$NON-NLS-2$
{
@@ -474,25 +500,28 @@ public class EquinoxBundleReader2 implements IBundleReader {
IObject revs = (IObject) bundleFragmentObject.resolveValue("module.revisions.revisions");//$NON-NLS-1$
IObject rev = CollectionExtractionUtils.extractList(revs).iterator().next();
- IObject caps = (IObject) rev.resolveValue("capabilities");//$NON-NLS-1$
- for (IObject o : CollectionExtractionUtils.extractList(caps))
+ ExtractedCollection extractedList = getCapabilities(rev);
+ if (extractedList != null)
{
- if ("equinox.fragment".equals(((IObject)(o.resolveValue("namespace"))).getClassSpecificName())) //$NON-NLS-1$ //$NON-NLS-2$
+ for (IObject o : extractedList)
{
- IObject attribs = (IObject)o.resolveValue("attributes"); //$NON-NLS-1$
- ExtractedMap kvs = CollectionExtractionUtils.extractMap(attribs);
- for (Entry<IObject,IObject> et : kvs)
+ if ("equinox.fragment".equals(((IObject)(o.resolveValue("namespace"))).getClassSpecificName())) //$NON-NLS-1$ //$NON-NLS-2$
{
- if ("equinox.fragment".equals(et.getKey().getClassSpecificName())) //$NON-NLS-1$
+ IObject attribs = (IObject)o.resolveValue("attributes"); //$NON-NLS-1$
+ ExtractedMap kvs = CollectionExtractionUtils.extractMap(attribs);
+ for (Entry<IObject,IObject> et : kvs)
{
- String hostName = et.getValue().getClassSpecificName();
- if (hostName != null)
+ if ("equinox.fragment".equals(et.getKey().getClassSpecificName())) //$NON-NLS-1$
{
- for (BundleDescriptor bd : bundleDescriptors.values())
+ String hostName = et.getValue().getClassSpecificName();
+ if (hostName != null)
{
- if (bd.getBundleName().equals(hostName) || bd.getBundleName().startsWith(hostName + " (")) //$NON-NLS-1$
+ for (BundleDescriptor bd : bundleDescriptors.values())
{
- return bd;
+ if (bd.getBundleName().equals(hostName) || bd.getBundleName().startsWith(hostName + " (")) //$NON-NLS-1$
+ {
+ return bd;
+ }
}
}
}
|
