Handle dependencies a little differently to avoid dangling references and
make sure to use the revision, not the wiring, to clean up dependencies. (FELIX-2950)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1148927 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleRevisionDependencies.java b/framework/src/main/java/org/apache/felix/framework/BundleRevisionDependencies.java
index d00c9dd..f2ea240 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleRevisionDependencies.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleRevisionDependencies.java
@@ -138,14 +138,17 @@
// get the capability list from the revision's wiring, which is
// in declared order (including fragments), and use it to create
// the provided wire list in declared order.
- List<BundleCapability> resolvedCaps =
- revision.getWiring().getCapabilities(namespace);
- for (BundleCapability resolvedCap : resolvedCaps)
+ BundleWiring wiring = revision.getWiring();
+ if (wiring != null)
{
- Set<BundleWire> dependentWires = providedCaps.get(resolvedCap);
- if (dependentWires != null)
+ List<BundleCapability> resolvedCaps = wiring.getCapabilities(namespace);
+ for (BundleCapability resolvedCap : resolvedCaps)
{
- providedWires.addAll(dependentWires);
+ Set<BundleWire> dependentWires = providedCaps.get(resolvedCap);
+ if (dependentWires != null)
+ {
+ providedWires.addAll(dependentWires);
+ }
}
}
}
@@ -164,11 +167,12 @@
// since their dependents are their hosts.
if (Util.isFragment(revision))
{
- if (revision.getWiring() != null)
+ BundleWiring wiring = revision.getWiring();
+ if (wiring != null)
{
- for (BundleWire wire : revision.getWiring().getRequiredWires(null))
+ for (BundleWire bw : wiring.getRequiredWires(null))
{
- result.add(wire.getProviderWiring().getBundle());
+ result.add(((BundleWireImpl) bw).getProvider().getBundle());
}
}
}
@@ -278,38 +282,34 @@
BundleWiring wiring = rev.getWiring();
if (wiring != null)
{
- for (BundleWire wire : wiring.getRequiredWires(null))
+ for (BundleWire bw : wiring.getRequiredWires(null))
{
- // The provider wiring may already be null if the framework
- // is shutting down, so don't worry about updating dependencies
- // in that case.
- if (wire.getProviderWiring() != null)
- {
- Map<BundleCapability, Set<BundleWire>> caps =
- m_dependentsMap.get(wire.getProviderWiring().getRevision());
- if (caps != null)
- {
- List<BundleCapability> gc = new ArrayList<BundleCapability>();
- for (Entry<BundleCapability, Set<BundleWire>> entry
- : caps.entrySet())
- {
- entry.getValue().remove(wire);
- if (entry.getValue().isEmpty())
- {
- gc.add(entry.getKey());
- }
- }
- for (BundleCapability cap : gc)
- {
- caps.remove(cap);
- }
- if (caps.isEmpty())
- {
// TODO: OSGi R4.4 - Eventually we won't need to use the impl type here,
// since the plan is to standardize on this method for the OBR spec.
- m_dependentsMap.remove(((BundleWireImpl) wire).getProvider());
+ Map<BundleCapability, Set<BundleWire>> caps =
+ m_dependentsMap.get(((BundleWireImpl) bw).getProvider());
+ if (caps != null)
+ {
+ List<BundleCapability> gc = new ArrayList<BundleCapability>();
+ for (Entry<BundleCapability, Set<BundleWire>> entry
+ : caps.entrySet())
+ {
+ entry.getValue().remove(bw);
+ if (entry.getValue().isEmpty())
+ {
+ gc.add(entry.getKey());
}
}
+ for (BundleCapability cap : gc)
+ {
+ caps.remove(cap);
+ }
+ if (caps.isEmpty())
+ {
+// TODO: OSGi R4.4 - Eventually we won't need to use the impl type here,
+// since the plan is to standardize on this method for the OBR spec.
+ m_dependentsMap.remove(((BundleWireImpl) bw).getProvider());
+ }
}
}
}
diff --git a/framework/src/main/java/org/apache/felix/framework/StatefulResolver.java b/framework/src/main/java/org/apache/felix/framework/StatefulResolver.java
index ebefdff..d03148f 100644
--- a/framework/src/main/java/org/apache/felix/framework/StatefulResolver.java
+++ b/framework/src/main/java/org/apache/felix/framework/StatefulResolver.java
@@ -56,6 +56,7 @@
import org.osgi.framework.wiring.BundleRequirement;
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.framework.wiring.BundleWire;
+import org.osgi.framework.wiring.BundleWiring;
class StatefulResolver
{
@@ -762,8 +763,6 @@
rw.getCapability());
bundleWires.add(bw);
- m_felix.getDependencies().addDependent(bw);
-
if (Util.isFragment(revision))
{
m_felix.getLogger().log(
@@ -861,8 +860,15 @@
BundleRevisionImpl revision = (BundleRevisionImpl) entry.getKey();
// Mark revision as resolved.
+ BundleWiring wiring = entry.getValue();
revision.resolve(entry.getValue());
+ // Record dependencies.
+ for (BundleWire bw : wiring.getRequiredWires(null))
+ {
+ m_felix.getDependencies().addDependent(bw);
+ }
+
// Update resolver state to remove substituted capabilities.
if (!Util.isFragment(revision))
{