Bug 575576 - BundleWiring and Wiring lists must be snapshot/mutable

Change-Id: I8e5626478ec54812e3267adb70edb3c07a63d9cc
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
Reviewed-on: https://git.eclipse.org/r/c/equinox/rt.equinox.framework/+/184329
Reviewed-by: BJ Hargrave <hargrave@us.ibm.com>
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleWiring.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleWiring.java
index bdd3398..50bfc53 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleWiring.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleWiring.java
@@ -13,6 +13,14 @@
  *******************************************************************************/
 package org.eclipse.osgi.container;
 
+import static org.eclipse.osgi.internal.container.InternalUtils.asCopy;
+import static org.eclipse.osgi.internal.container.InternalUtils.asListBundleCapability;
+import static org.eclipse.osgi.internal.container.InternalUtils.asListBundleRequirement;
+import static org.eclipse.osgi.internal.container.InternalUtils.asListBundleWire;
+import static org.eclipse.osgi.internal.container.InternalUtils.asListCapability;
+import static org.eclipse.osgi.internal.container.InternalUtils.asListRequirement;
+import static org.eclipse.osgi.internal.container.InternalUtils.asListWire;
+
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -27,7 +35,6 @@
 import java.util.concurrent.atomic.AtomicReference;
 import org.eclipse.osgi.container.ModuleRevisionBuilder.GenericInfo;
 import org.eclipse.osgi.internal.container.AtomicLazyInitializer;
-import org.eclipse.osgi.internal.container.InternalUtils;
 import org.eclipse.osgi.internal.container.NamespaceList;
 import org.osgi.framework.AdminPermission;
 import org.osgi.framework.Bundle;
@@ -108,8 +115,9 @@
 	}
 
 	/**
-	 * Returns the same result as {@link #getCapabilities(String)} except
-	 * uses type ModuleCapability.
+	 * Returns the same result as {@link #getCapabilities(String)} except uses type
+	 * ModuleCapability and the returned list is unmodifiable.
+	 * 
 	 * @param namespace the namespace
 	 * @return the capabilities
 	 * @see #getCapabilities(String)
@@ -122,8 +130,9 @@
 	}
 
 	/**
-	 * Returns the same result as {@link #getRequirements(String)} except
-	 * uses type ModuleRequirement.
+	 * Returns the same result as {@link #getRequirements(String)} except uses type
+	 * ModuleRequirement and the returned list is unmodifiable.
+	 * 
 	 * @param namespace the namespace
 	 * @return the requirements
 	 * @see #getRequirements(String)
@@ -153,18 +162,19 @@
 
 	@Override
 	public List<BundleCapability> getCapabilities(String namespace) {
-		return InternalUtils.asListBundleCapability(getModuleCapabilities(namespace));
+		return asCopy(asListBundleCapability(getModuleCapabilities(namespace)));
 
 	}
 
 	@Override
 	public List<BundleRequirement> getRequirements(String namespace) {
-		return InternalUtils.asListBundleRequirement(getModuleRequirements(namespace));
+		return asCopy(asListBundleRequirement(getModuleRequirements(namespace)));
 	}
 
 	/**
-	 * Returns the same result as {@link #getProvidedWires(String)} except
-	 * uses type ModuleWire.
+	 * Returns the same result as {@link #getProvidedWires(String)} except uses type
+	 * ModuleWire and the returned list is unmodifiable.
+	 * 
 	 * @param namespace the namespace
 	 * @return the wires
 	 * @see #getProvidedWires(String)
@@ -178,8 +188,9 @@
 	}
 
 	/**
-	 * Returns the same result as {@link #getRequiredWires(String)} except
-	 * uses type ModuleWire.
+	 * Returns the same result as {@link #getRequiredWires(String)} except uses type
+	 * ModuleWire and the returned list is unmodifiable.
+	 * 
 	 * @param namespace the namespace
 	 * @return the wires
 	 * @see #getRequiredWires(String)
@@ -210,12 +221,12 @@
 
 	@Override
 	public List<BundleWire> getProvidedWires(String namespace) {
-		return InternalUtils.asListBundleWire(getWires(namespace, providedWires));
+		return asCopy(asListBundleWire(getWires(namespace, providedWires)));
 	}
 
 	@Override
 	public List<BundleWire> getRequiredWires(String namespace) {
-		return InternalUtils.asListBundleWire(getWires(namespace, requiredWires));
+		return asCopy(asListBundleWire(getWires(namespace, requiredWires)));
 	}
 
 	private List<ModuleWire> getWires(String namespace, NamespaceList<ModuleWire> wires) {
@@ -297,22 +308,22 @@
 
 	@Override
 	public List<Capability> getResourceCapabilities(String namespace) {
-		return InternalUtils.asListCapability(getCapabilities(namespace));
+		return asCopy(asListCapability(getModuleCapabilities(namespace)));
 	}
 
 	@Override
 	public List<Requirement> getResourceRequirements(String namespace) {
-		return InternalUtils.asListRequirement(getRequirements(namespace));
+		return asCopy(asListRequirement(getModuleRequirements(namespace)));
 	}
 
 	@Override
 	public List<Wire> getProvidedResourceWires(String namespace) {
-		return InternalUtils.asListWire(getWires(namespace, providedWires));
+		return asCopy(asListWire(getWires(namespace, providedWires)));
 	}
 
 	@Override
 	public List<Wire> getRequiredResourceWires(String namespace) {
-		return InternalUtils.asListWire(getWires(namespace, requiredWires));
+		return asCopy(asListWire(getWires(namespace, requiredWires)));
 	}
 
 	@Override
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/container/InternalUtils.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/container/InternalUtils.java
index 3e6626c..e9daaac 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/container/InternalUtils.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/container/InternalUtils.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012, 2013 IBM Corporation and others.
+ * Copyright (c) 2012, 2021 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -15,6 +15,7 @@
 
 import java.security.Permission;
 import java.security.SecureRandom;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
@@ -40,6 +41,10 @@
 
 public class InternalUtils {
 
+	public static <T> List<T> asCopy(List<T> list) {
+		return new ArrayList<>(list);
+	}
+
 	/**
 	 * Coerce the generic type of a list from List<BundleCapability>
 	 * to List<Capability>
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/DTOBuilder.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/DTOBuilder.java
index 86ee2d0..9a643db 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/DTOBuilder.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/DTOBuilder.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012, 2016 IBM Corporation and others.
+ * Copyright (c) 2012, 2021 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -24,6 +24,10 @@
 import java.util.ListIterator;
 import java.util.Map;
 import java.util.Set;
+import org.eclipse.osgi.container.ModuleCapability;
+import org.eclipse.osgi.container.ModuleRequirement;
+import org.eclipse.osgi.container.ModuleWire;
+import org.eclipse.osgi.container.ModuleWiring;
 import org.osgi.dto.DTO;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -42,7 +46,6 @@
 import org.osgi.framework.wiring.BundleRequirement;
 import org.osgi.framework.wiring.BundleRevision;
 import org.osgi.framework.wiring.BundleRevisions;
-import org.osgi.framework.wiring.BundleWire;
 import org.osgi.framework.wiring.BundleWiring;
 import org.osgi.framework.wiring.dto.BundleRevisionDTO;
 import org.osgi.framework.wiring.dto.BundleWireDTO;
@@ -145,7 +148,7 @@
 		return dto;
 	}
 
-	private List<CapabilityRefDTO> getListCapabilityRefDTO(List<BundleCapability> caps) {
+	private List<CapabilityRefDTO> getListCapabilityRefDTO(List<ModuleCapability> caps) {
 		if (caps == null) {
 			return null;
 		}
@@ -190,18 +193,18 @@
 		return dto;
 	}
 
-	private List<RequirementRefDTO> getListRequirementRefDTO(List<BundleRequirement> reqs) {
+	private List<RequirementRefDTO> getListRequirementRefDTO(List<ModuleRequirement> reqs) {
 		if (reqs == null) {
 			return null;
 		}
 		List<RequirementRefDTO> dtos = newList(reqs.size());
-		for (BundleRequirement req : reqs) {
+		for (ModuleRequirement req : reqs) {
 			dtos.add(getRequirementRefDTO(req));
 		}
 		return dtos;
 	}
 
-	private RequirementRefDTO getRequirementRefDTO(BundleRequirement req) {
+	private RequirementRefDTO getRequirementRefDTO(ModuleRequirement req) {
 		if (req == null) {
 			return null;
 		}
@@ -228,13 +231,13 @@
 		if (revision == null) {
 			return null;
 		}
-		BundleWiringDTO dto = new DTOBuilder().getBundleWiringDTO(revision.getWiring());
+		BundleWiringDTO dto = new DTOBuilder().getBundleWiringDTO((ModuleWiring) revision.getWiring());
 		return dto;
 	}
 
-	public static FrameworkWiringDTO newFrameworkWiringDTO(Collection<BundleWiring> allWirings) {
+	public static FrameworkWiringDTO newFrameworkWiringDTO(Collection<ModuleWiring> allWirings) {
 		DTOBuilder builder = new DTOBuilder();
-		for (BundleWiring wiring : allWirings) {
+		for (ModuleWiring wiring : allWirings) {
 			builder.getBundleWiringNodeDTO(wiring);
 		}
 		FrameworkWiringDTO dto = new FrameworkWiringDTO();
@@ -243,7 +246,7 @@
 		return dto;
 	}
 
-	private BundleWiringDTO getBundleWiringDTO(BundleWiring wiring) {
+	private BundleWiringDTO getBundleWiringDTO(ModuleWiring wiring) {
 		if (wiring == null) {
 			return null;
 		}
@@ -255,7 +258,7 @@
 		return dto;
 	}
 
-	private int getWiringId(BundleWiring wiring) {
+	private int getWiringId(ModuleWiring wiring) {
 		BundleWiringDTO.NodeDTO dto = getBundleWiringNodeDTO(wiring);
 		if (dto == null) {
 			return 0;
@@ -263,7 +266,7 @@
 		return dto.id;
 	}
 
-	private BundleWiringDTO.NodeDTO getBundleWiringNodeDTO(BundleWiring wiring) {
+	private BundleWiringDTO.NodeDTO getBundleWiringNodeDTO(ModuleWiring wiring) {
 		if (wiring == null) {
 			return null;
 		}
@@ -277,25 +280,25 @@
 		dto.current = wiring.isCurrent();
 		dto.inUse = wiring.isInUse();
 		dto.resource = getResourceId(wiring.getRevision());
-		dto.capabilities = getListCapabilityRefDTO(wiring.getCapabilities(null));
-		dto.requirements = getListRequirementRefDTO(wiring.getRequirements(null));
-		dto.providedWires = getListBundleWireDTO(wiring.getProvidedWires(null));
-		dto.requiredWires = getListBundleWireDTO(wiring.getRequiredWires(null));
+		dto.capabilities = getListCapabilityRefDTO(wiring.getModuleCapabilities(null));
+		dto.requirements = getListRequirementRefDTO(wiring.getModuleRequirements(null));
+		dto.providedWires = getListBundleWireDTO(wiring.getProvidedModuleWires(null));
+		dto.requiredWires = getListBundleWireDTO(wiring.getRequiredModuleWires(null));
 		return dto;
 	}
 
-	private List<WireDTO> getListBundleWireDTO(List<BundleWire> wires) {
+	private List<WireDTO> getListBundleWireDTO(List<ModuleWire> wires) {
 		if (wires == null) {
 			return null;
 		}
 		List<WireDTO> dtos = newList(wires.size());
-		for (BundleWire wire : wires) {
+		for (ModuleWire wire : wires) {
 			dtos.add(getBundleWireDTO(wire));
 		}
 		return dtos;
 	}
 
-	private BundleWireDTO getBundleWireDTO(BundleWire wire) {
+	private BundleWireDTO getBundleWireDTO(ModuleWire wire) {
 		if (wire == null) {
 			return null;
 		}
@@ -317,7 +320,7 @@
 		final int size = revs.size();
 		List<BundleWiringDTO> dtos = new ArrayList<>(size);
 		for (int i = 0; i < size; i++) {
-			BundleWiring wiring = revs.get(i).getWiring();
+			ModuleWiring wiring = (ModuleWiring) revs.get(i).getWiring();
 			if (wiring != null) {
 				dtos.add(new DTOBuilder().getBundleWiringDTO(wiring)); // use new DTOBuilder for each wiring dto
 			}
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxBundle.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxBundle.java
index 9ee0c0e..6f8e306 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxBundle.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxBundle.java
@@ -921,17 +921,17 @@
 			if (FrameworkWiringDTO.class.equals(adapterType)) {
 				readLock();
 				try {
-					Set<BundleWiring> allWirings = new HashSet<>();
+					Set<ModuleWiring> allWirings = new HashSet<>();
 					for (Module m : module.getContainer().getModules()) {
-						for (BundleRevision revision : m.getRevisions().getRevisions()) {
-							BundleWiring wiring = revision.getWiring();
+						for (ModuleRevision revision : m.getRevisions().getModuleRevisions()) {
+							ModuleWiring wiring = revision.getWiring();
 							if (wiring != null) {
 								allWirings.add(wiring);
 							}
 						}
 					}
 					for (ModuleRevision revision : module.getContainer().getRemovalPending()) {
-						BundleWiring wiring = revision.getWiring();
+						ModuleWiring wiring = revision.getWiring();
 						if (wiring != null) {
 							allWirings.add(wiring);
 						}
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/PackageAdminImpl.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/PackageAdminImpl.java
index e78a9c2..a440206 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/PackageAdminImpl.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/PackageAdminImpl.java
@@ -23,7 +23,9 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import org.eclipse.osgi.container.ModuleCapability;
 import org.eclipse.osgi.container.ModuleContainer;
+import org.eclipse.osgi.container.ModuleWire;
 import org.eclipse.osgi.container.ModuleWiring;
 import org.eclipse.osgi.internal.container.Capabilities;
 import org.eclipse.osgi.internal.container.InternalUtils;
@@ -40,8 +42,6 @@
 import org.osgi.framework.wiring.BundleCapability;
 import org.osgi.framework.wiring.BundleRevision;
 import org.osgi.framework.wiring.BundleRevisions;
-import org.osgi.framework.wiring.BundleWire;
-import org.osgi.framework.wiring.BundleWiring;
 import org.osgi.framework.wiring.FrameworkWiring;
 import org.osgi.resource.Namespace;
 import org.osgi.resource.Requirement;
@@ -69,11 +69,12 @@
 
 		Collection<ExportedPackage> allExports = new ArrayList<>();
 		for (BundleRevision revision : revisions) {
-			BundleWiring wiring = revision.getWiring();
+			ModuleWiring wiring = (ModuleWiring) revision.getWiring();
 			if (wiring != null) {
-				List<BundleCapability> providedPackages = wiring.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE);
+				List<ModuleCapability> providedPackages = wiring
+						.getModuleCapabilities(PackageNamespace.PACKAGE_NAMESPACE);
 				if (providedPackages != null) {
-					for (BundleCapability providedPackage : providedPackages) {
+					for (ModuleCapability providedPackage : providedPackages) {
 						allExports.add(new ExportedPackageImpl(providedPackage, wiring));
 					}
 				}
@@ -114,16 +115,16 @@
 		InternalUtils.filterCapabilityPermissions(packageCaps);
 		List<ExportedPackage> result = new ArrayList<>();
 		for (BundleCapability capability : packageCaps) {
-			BundleWiring wiring = capability.getRevision().getWiring();
+			ModuleWiring wiring = (ModuleWiring) capability.getRevision().getWiring();
 			if (wiring != null) {
-				Collection<BundleWiring> wirings = Collections.emptyList();
+				Collection<ModuleWiring> wirings = Collections.emptyList();
 				if ((capability.getRevision().getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
 					// This is a fragment, just get all the host wirings
-					List<BundleWire> hostWires = wiring.getRequiredWires(HostNamespace.HOST_NAMESPACE);
+					List<ModuleWire> hostWires = wiring.getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
 					if (hostWires != null && !hostWires.isEmpty()) {
 						wirings = new ArrayList<>(hostWires.size());
-						for (BundleWire hostWire : hostWires) {
-							BundleWiring hostWiring = hostWire.getProviderWiring();
+						for (ModuleWire hostWire : hostWires) {
+							ModuleWiring hostWiring = hostWire.getProviderWiring();
 							if (hostWiring != null) {
 								wirings.add(hostWiring);
 							}
@@ -133,11 +134,11 @@
 					// just a single host wiring
 					wirings = Collections.singletonList(wiring);
 				}
-				for (BundleWiring moduleWiring : wirings) {
+				for (ModuleWiring moduleWiring : wirings) {
 					Object pkgName = capability.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
 					if (pkgName instanceof String
-							&& !((ModuleWiring) moduleWiring).isSubstitutedPackage((String) pkgName)) {
-						result.add(new ExportedPackageImpl(capability, moduleWiring));
+							&& !moduleWiring.isSubstitutedPackage((String) pkgName)) {
+						result.add(new ExportedPackageImpl((ModuleCapability) capability, moduleWiring));
 					}
 				}
 			}
@@ -165,9 +166,9 @@
 		InternalUtils.filterCapabilityPermissions(bundleCaps);
 		Collection<RequiredBundle> result = new ArrayList<>();
 		for (BundleCapability capability : bundleCaps) {
-			BundleWiring wiring = capability.getRevision().getWiring();
+			ModuleWiring wiring = (ModuleWiring) capability.getRevision().getWiring();
 			if (wiring != null) {
-				result.add(new RequiredBundleImpl(capability, wiring));
+				result.add(new RequiredBundleImpl((ModuleCapability) capability, wiring));
 			}
 		}
 		return result.isEmpty() ? null : result.toArray(new RequiredBundle[result.size()]);
@@ -209,17 +210,17 @@
 
 	@Override
 	public Bundle[] getFragments(Bundle bundle) {
-		BundleWiring wiring = getWiring(bundle);
+		ModuleWiring wiring = getWiring(bundle);
 		if (wiring == null) {
 			return null;
 		}
-		List<BundleWire> hostWires = wiring.getProvidedWires(HostNamespace.HOST_NAMESPACE);
+		List<ModuleWire> hostWires = wiring.getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
 		if (hostWires == null) {
 			// we don't hold locks while checking the graph, just return if no longer valid
 			return null;
 		}
 		Collection<Bundle> fragments = new ArrayList<>(hostWires.size());
-		for (BundleWire wire : hostWires) {
+		for (ModuleWire wire : hostWires) {
 			Bundle fragment = wire.getRequirer().getBundle();
 			if (fragment != null) {
 				fragments.add(fragment);
@@ -230,17 +231,17 @@
 
 	@Override
 	public Bundle[] getHosts(Bundle bundle) {
-		BundleWiring wiring = getWiring(bundle);
+		ModuleWiring wiring = getWiring(bundle);
 		if (wiring == null) {
 			return null;
 		}
-		List<BundleWire> hostWires = wiring.getRequiredWires(HostNamespace.HOST_NAMESPACE);
+		List<ModuleWire> hostWires = wiring.getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
 		if (hostWires == null) {
 			// we don't hold locks while checking the graph, just return if no longer valid
 			return null;
 		}
 		Collection<Bundle> hosts = new ArrayList<>(hostWires.size());
-		for (BundleWire wire : hostWires) {
+		for (ModuleWire wire : hostWires) {
 			Bundle host = wire.getProvider().getBundle();
 			if (host != null) {
 				hosts.add(host);
@@ -249,12 +250,12 @@
 		return hosts.isEmpty() ? null : hosts.toArray(new Bundle[hosts.size()]);
 	}
 
-	private BundleWiring getWiring(Bundle bundle) {
+	private ModuleWiring getWiring(Bundle bundle) {
 		BundleRevision current = bundle.adapt(BundleRevision.class);
 		if (current == null) {
 			return null;
 		}
-		return current.getWiring();
+		return (ModuleWiring) current.getWiring();
 	}
 
 	@Override
@@ -281,10 +282,10 @@
 
 	static class ExportedPackageImpl implements ExportedPackage {
 
-		private final BundleCapability packageCapability;
-		private final BundleWiring providerWiring;
+		private final ModuleCapability packageCapability;
+		private final ModuleWiring providerWiring;
 
-		public ExportedPackageImpl(BundleCapability packageCapability, BundleWiring providerWiring) {
+		public ExportedPackageImpl(ModuleCapability packageCapability, ModuleWiring providerWiring) {
 			this.packageCapability = packageCapability;
 			this.providerWiring = providerWiring;
 		}
@@ -311,15 +312,16 @@
 			String packageName = getName();
 			addRequirers(importing, providerWiring, packageName);
 
-			List<BundleWire> providedPackages = providerWiring.getProvidedWires(PackageNamespace.PACKAGE_NAMESPACE);
+			List<ModuleWire> providedPackages = providerWiring
+					.getProvidedModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
 			if (providedPackages == null) {
 				// we don't hold locks while checking the graph, just return if no longer valid
 				return null;
 			}
-			for (BundleWire packageWire : providedPackages) {
+			for (ModuleWire packageWire : providedPackages) {
 				if (packageCapability.equals(packageWire.getCapability())) {
 					importing.add(packageWire.getRequirer().getBundle());
-					if (((ModuleWiring) packageWire.getRequirerWiring()).isSubstitutedPackage(packageName)) {
+					if (packageWire.getRequirerWiring().isSubstitutedPackage(packageName)) {
 						addRequirers(importing, packageWire.getRequirerWiring(), packageName);
 					}
 				}
@@ -327,13 +329,13 @@
 			return importing.toArray(new Bundle[importing.size()]);
 		}
 
-		private static void addRequirers(Set<Bundle> importing, BundleWiring wiring, String packageName) {
-			List<BundleWire> requirerWires = wiring.getProvidedWires(BundleNamespace.BUNDLE_NAMESPACE);
+		private static void addRequirers(Set<Bundle> importing, ModuleWiring wiring, String packageName) {
+			List<ModuleWire> requirerWires = wiring.getProvidedModuleWires(BundleNamespace.BUNDLE_NAMESPACE);
 			if (requirerWires == null) {
 				// we don't hold locks while checking the graph, just return if no longer isInUse
 				return;
 			}
-			for (BundleWire requireBundleWire : requirerWires) {
+			for (ModuleWire requireBundleWire : requirerWires) {
 				Bundle requirer = requireBundleWire.getRequirer().getBundle();
 				if (importing.contains(requirer)) {
 					continue;
@@ -342,19 +344,19 @@
 
 				// if reexported then need to add any requirers of the reexporter
 				String reExport = requireBundleWire.getRequirement().getDirectives().get(BundleNamespace.REQUIREMENT_VISIBILITY_DIRECTIVE);
-				BundleWiring requirerWiring = requireBundleWire.getRequirerWiring();
+				ModuleWiring requirerWiring = requireBundleWire.getRequirerWiring();
 				if (BundleNamespace.VISIBILITY_REEXPORT.equals(reExport)) {
 					addRequirers(importing, requirerWiring, packageName);
 				}
 				// also need to add any importers of the same package as the wiring exports; case of aggregations
 				if (!requirerWiring.equals(wiring)) {
-					List<BundleWire> providedPackages = requirerWiring.getProvidedWires(PackageNamespace.PACKAGE_NAMESPACE);
+					List<ModuleWire> providedPackages = requirerWiring
+							.getProvidedModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
 					if (providedPackages != null) {
-						for (BundleWire packageWire : providedPackages) {
+						for (ModuleWire packageWire : providedPackages) {
 							if (packageName.equals(packageWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE))) {
 								importing.add(packageWire.getRequirer().getBundle());
-								if (((ModuleWiring) packageWire.getRequirerWiring())
-										.isSubstitutedPackage(packageName)) {
+								if (packageWire.getRequirerWiring().isSubstitutedPackage(packageName)) {
 									addRequirers(importing, packageWire.getRequirerWiring(), packageName);
 								}
 							}
@@ -391,10 +393,10 @@
 	}
 
 	private static class RequiredBundleImpl implements RequiredBundle {
-		private final BundleCapability bundleCapability;
-		private final BundleWiring providerWiring;
+		private final ModuleCapability bundleCapability;
+		private final ModuleWiring providerWiring;
 
-		public RequiredBundleImpl(BundleCapability bundleCapability, BundleWiring providerWiring) {
+		public RequiredBundleImpl(ModuleCapability bundleCapability, ModuleWiring providerWiring) {
 			this.bundleCapability = bundleCapability;
 			this.providerWiring = providerWiring;
 		}
@@ -423,13 +425,13 @@
 			return requiring.toArray(new Bundle[requiring.size()]);
 		}
 
-		private static void addRequirers(Set<Bundle> requiring, BundleWiring providerWiring) {
-			List<BundleWire> requirerWires = providerWiring.getProvidedWires(BundleNamespace.BUNDLE_NAMESPACE);
+		private static void addRequirers(Set<Bundle> requiring, ModuleWiring providerWiring) {
+			List<ModuleWire> requirerWires = providerWiring.getProvidedModuleWires(BundleNamespace.BUNDLE_NAMESPACE);
 			if (requirerWires == null) {
 				// we don't hold locks while checking the graph, just return if no longer isInUse
 				return;
 			}
-			for (BundleWire requireBundleWire : requirerWires) {
+			for (ModuleWire requireBundleWire : requirerWires) {
 				Bundle requirer = requireBundleWire.getRequirer().getBundle();
 				if (requiring.contains(requirer)) {
 					continue;
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/buddy/GlobalPolicy.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/buddy/GlobalPolicy.java
index a346ee2..e3b3eda 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/buddy/GlobalPolicy.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/buddy/GlobalPolicy.java
@@ -21,6 +21,7 @@
 import java.util.Enumeration;
 import java.util.Map;
 import org.eclipse.osgi.container.ModuleContainer;
+import org.eclipse.osgi.container.ModuleWiring;
 import org.eclipse.osgi.internal.container.Capabilities;
 import org.eclipse.osgi.internal.loader.BundleLoader;
 import org.osgi.framework.Bundle;
@@ -29,7 +30,6 @@
 import org.osgi.framework.wiring.BundleCapability;
 import org.osgi.framework.wiring.BundleRevision;
 import org.osgi.framework.wiring.BundleWire;
-import org.osgi.framework.wiring.BundleWiring;
 import org.osgi.framework.wiring.FrameworkWiring;
 import org.osgi.resource.Namespace;
 
@@ -88,8 +88,8 @@
 		for (BundleCapability pkg : packages) {
 			if ((pkg.getRevision().getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
 				// use the hosts
-				BundleWiring wiring = pkg.getRevision().getWiring();
-				for (BundleWire hostWire : wiring.getRequiredWires(HostNamespace.HOST_NAMESPACE)) {
+				ModuleWiring wiring = (ModuleWiring) pkg.getRevision().getWiring();
+				for (BundleWire hostWire : wiring.getRequiredModuleWires(HostNamespace.HOST_NAMESPACE)) {
 					result.add(hostWire.getProvider().getBundle());
 				}
 			} else {