Rollback 1365509 since it causes a failure in the weaving hook tests of the CT. (FELIX-3609)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1365665 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java b/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
index ba7e5e5..c21ba5b 100644
--- a/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
+++ b/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
@@ -64,8 +64,8 @@
         org.osgi.service.url.URLStreamHandlerService.class,
         java.net.ContentHandler.class
     };
-    private final Map<Class<?>, TreeSet<ServiceReference<?>>> m_allHooks =
-        new HashMap<Class<?>, TreeSet<ServiceReference<?>>>();
+    private final Map<Class<?>, Set<ServiceReference<?>>> m_allHooks =
+        new HashMap<Class<?>, Set<ServiceReference<?>>>();
 
     public ServiceRegistry(Logger logger, ServiceRegistryCallbacks callbacks)
     {
@@ -701,10 +701,10 @@
             {
                 synchronized (m_allHooks)
                 {
-                    TreeSet<ServiceReference<?>> hooks = m_allHooks.get(hookClass);
+                    Set<ServiceReference<?>> hooks = m_allHooks.get(hookClass);
                     if (hooks == null)
                     {
-                        hooks = new TreeSet<ServiceReference<?>>(Collections.reverseOrder());
+                        hooks = new HashSet<ServiceReference<?>>();
                         m_allHooks.put(hookClass, hooks);
                     }
                     hooks.add(ref);
@@ -743,18 +743,19 @@
     {
         synchronized (m_allHooks)
         {
-            TreeSet<ServiceReference<?>> hooks = m_allHooks.get(hookClass);
+            Set<ServiceReference<?>> hooks = m_allHooks.get(hookClass);
             if (hooks != null)
             {
-                SortedSet<ServiceReference<?>> sorted = (SortedSet<ServiceReference<?>>) hooks.clone();
+                SortedSet sorted = new TreeSet<ServiceReference<?>>(Collections.reverseOrder());
+                sorted.addAll(hooks);
                 return asTypedSortedSet(sorted);
             }
-            return Collections.emptySet();
+            return Collections.EMPTY_SET;
         }
     }
 
     private static <S> SortedSet<ServiceReference<S>> asTypedSortedSet(
-            SortedSet<ServiceReference<?>> ss)
+        SortedSet<ServiceReference<?>> ss)
     {
         return (SortedSet<ServiceReference<S>>) (SortedSet) ss;
     }