Added an IllegalStateException in ServiceDependencyImpl in case a swap is about to be performed with two services having the same service ranking.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1333327 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ServiceDependencyImpl.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ServiceDependencyImpl.java
index 09b20c0..499bb14 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ServiceDependencyImpl.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ServiceDependencyImpl.java
@@ -715,6 +715,14 @@
private void invokeSwappedCallback(DependencyService component, ServiceReference previousReference, Object previous, ServiceReference currentServiceReference,
Object current) {
+ // sanity check on the service references
+ Integer oldRank = (Integer) previousReference.getProperty(Constants.SERVICE_RANKING);
+ Integer newRank = (Integer) currentServiceReference.getProperty(Constants.SERVICE_RANKING);
+
+ if (oldRank != null && newRank != null && oldRank.equals(newRank)) {
+ throw new IllegalStateException("Attempt to swap a service for a service with the same rank! previousReference: " + previousReference + ", currentReference: " + currentServiceReference);
+ }
+
component.invokeCallbackMethod(getCallbackInstances(component), m_callbackSwapped, new Class[][] { { m_trackedServiceName, m_trackedServiceName },
{ Object.class, Object.class }, { ServiceReference.class, m_trackedServiceName, ServiceReference.class, m_trackedServiceName },
{ ServiceReference.class, Object.class, ServiceReference.class, Object.class } }, new Object[][] { { previous, current },