Fix an issue when the requester doesn't have a wire but the provider does and the service is a service factory. In that case, we should see whether the provider has access and if so whether the class is the same as of the requester. (FELIX-1600)

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@820985 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java b/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java
index f34a333..690a8a2 100644
--- a/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java
@@ -442,9 +442,10 @@
             // the exporting modules from the package wiring to determine if we
             // need to filter the service reference.
 
-            // Case 1: Always include service reference.
-            if (requesterWire == null)
+            // Case r=null && p = null
+            if ((requesterWire == null) && (providerWire == null))
             {
+                // if r has no access then true, otherwise service registration must have same class as r
                 try
                 {
                     Class requestClass = requesterModule.getClassByDelegation(className);
@@ -455,11 +456,43 @@
                     allow = true;
                 }
             }
-
-            // Case 2: Only include service reference if the provider and
-            // requester are using the same class.
-            else if (providerWire == null)
+            else if ((requesterWire == null) && (providerWire != null))
             {
+                // r = null && p != null && p == r
+                if (providerWire.getExporter().equals(requesterModule))
+                {
+                    allow = true;
+                }
+                // otherwise (r = null && p != null && p != r)
+                else
+                {
+                    // if r has no access true or if r's class is same as provider wire's class true (otherwise still possibly check registration's class)
+                    try
+                    {
+                        Class requestClass = requesterModule.getClassByDelegation(className);
+                        try
+                        {
+                            allow = providerWire.getClass(className) == requestClass;
+                        }
+                        catch (Exception ex)
+                        {
+                            allow = false;
+                        }
+                        if (!allow)
+                        {
+                            allow = getRegistration().isClassAccessible(requestClass);
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        allow = true;
+                    }
+                }
+            }
+            else if ((requesterWire != null) && (providerWire == null))
+            {
+                // Only include service reference if the provider and
+                // requester are using the same class.
                 // If the provider is the exporter of the requester's package, then check
                 // if the requester is wired to the latest version of the provider, if so
                 // then allow else don't (the provider has been updated but not refreshed).
@@ -488,10 +521,10 @@
                     }
                 }
             }
-            // Case 3: Include service reference if the wires have the
-            // same source module.
             else
             {
+                // Include service reference if the wires have the
+                // same source module.
                 allow = providerWire.getExporter().equals(requesterWire.getExporter());
             }