Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBJ Hargrave2010-11-12 01:53:04 +0000
committerBJ Hargrave2010-11-12 01:53:04 +0000
commitf6a7400db070633059394c4658e84f00aca67144 (patch)
tree5b90d2d385ddfc3e8bdfd82a6080ee343503b220
parent98caa11e260e13024d2eddb60e11a1cb209972f7 (diff)
downloadrt.equinox.framework-f6a7400db070633059394c4658e84f00aca67144.tar.gz
rt.equinox.framework-f6a7400db070633059394c4658e84f00aca67144.tar.xz
rt.equinox.framework-f6a7400db070633059394c4658e84f00aca67144.zip
bug 329940: Detect and handle recursive calls for the same bundle to ServiceFactory.getServicev20101115
-rw-r--r--bundles/org.eclipse.osgi/.settings/.api_filters9
-rwxr-xr-xbundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/serviceregistry/ServiceUse.java17
-rw-r--r--bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/ServiceException.java7
-rw-r--r--bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/core/ExternalMessages.properties1
-rw-r--r--bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/core/Msg.java1
5 files changed, 35 insertions, 0 deletions
diff --git a/bundles/org.eclipse.osgi/.settings/.api_filters b/bundles/org.eclipse.osgi/.settings/.api_filters
index 6a270af44..b02b47447 100644
--- a/bundles/org.eclipse.osgi/.settings/.api_filters
+++ b/bundles/org.eclipse.osgi/.settings/.api_filters
@@ -809,6 +809,15 @@
</message_arguments>
</filter>
</resource>
+<resource path="osgi/src/org/osgi/framework/ServiceException.java" type="org.osgi.framework.ServiceException">
+<filter comment="Ignore OSGi API" id="1141899266">
+<message_arguments>
+<message_argument value="1.6"/>
+<message_argument value="3.7"/>
+<message_argument value="FACTORY_RECURSION"/>
+</message_arguments>
+</filter>
+</resource>
<resource path="osgi/src/org/osgi/framework/ServiceReference.java" type="org.osgi.framework.ServiceReference">
<filter comment="Ignore OSGi API" id="403853384">
<message_arguments>
diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/serviceregistry/ServiceUse.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/serviceregistry/ServiceUse.java
index e8b4988c2..5651dacca 100755
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/serviceregistry/ServiceUse.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/serviceregistry/ServiceUse.java
@@ -43,6 +43,9 @@ public class ServiceUse<S> {
/** bundle's use count for this service */
/* @GuardedBy("this") */
private int useCount;
+ /** true if we are calling the factory getService method. Used to detect recursion. */
+ /* @GuardedBy("this") */
+ private boolean factoryInUse;
/** Internal framework object. */
@@ -56,6 +59,7 @@ public class ServiceUse<S> {
*/
ServiceUse(BundleContextImpl context, ServiceRegistrationImpl<S> registration) {
this.useCount = 0;
+ this.factoryInUse = false;
S service = registration.getServiceObject();
if (service instanceof ServiceFactory<?>) {
@SuppressWarnings("unchecked")
@@ -116,6 +120,17 @@ public class ServiceUse<S> {
if (Debug.DEBUG_SERVICES) {
Debug.println("getService[factory=" + registration.getBundle() + "](" + context.getBundleImpl() + "," + registration + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
+ // check for recursive call
+ if (factoryInUse == true) {
+ if (Debug.DEBUG_SERVICES) {
+ Debug.println(factory + ".getService() recursively called."); //$NON-NLS-1$
+ }
+
+ ServiceException se = new ServiceException(NLS.bind(Msg.SERVICE_FACTORY_RECURSION, factory.getClass().getName(), "getService"), ServiceException.FACTORY_RECURSION); //$NON-NLS-1$
+ context.getFramework().publishFrameworkEvent(FrameworkEvent.WARNING, registration.getBundle(), se);
+ return null;
+ }
+ factoryInUse = true;
final S service;
try {
service = AccessController.doPrivileged(new PrivilegedAction<S>() {
@@ -133,6 +148,8 @@ public class ServiceUse<S> {
ServiceException se = new ServiceException(NLS.bind(Msg.SERVICE_FACTORY_EXCEPTION, factory.getClass().getName(), "getService"), ServiceException.FACTORY_EXCEPTION, t); //$NON-NLS-1$
context.getFramework().publishFrameworkEvent(FrameworkEvent.ERROR, registration.getBundle(), se);
return null;
+ } finally {
+ factoryInUse = false;
}
if (service == null) {
diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/ServiceException.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/ServiceException.java
index 728db456d..35e0e88a7 100644
--- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/ServiceException.java
+++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/ServiceException.java
@@ -68,6 +68,13 @@ public class ServiceException extends RuntimeException {
* An error occurred invoking a remote service.
*/
public static final int REMOTE = 5;
+ /**
+ * The service factory resulted in a recursive call to itself for the
+ * requesting bundle.
+ *
+ * @since 1.6
+ */
+ public static final int FACTORY_RECURSION = 6;
/**
* Creates a {@code ServiceException} with the specified message and
diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/core/ExternalMessages.properties b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/core/ExternalMessages.properties
index 1c73f44e1..8ed29eda5 100644
--- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/core/ExternalMessages.properties
+++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/core/ExternalMessages.properties
@@ -46,6 +46,7 @@ MANIFEST_INVALID_LINE_NOCOLON=The manifest line \"{0}\" is invalid; it has no co
MANIFEST_INVALID_HEADER_EXCEPTION=Invalid manifest header {0}: \"{1}\"
MANIFEST_IOEXCEPTION=An error occurred while reading the manifest file.
SERVICE_FACTORY_EXCEPTION=Exception in {0}.{1}()
+SERVICE_FACTORY_RECURSION=Recursive ServiceFactory call in {0}.{1}()
SERVICE_NOT_INSTANCEOF_CLASS_EXCEPTION=The service object is not an instance of the service class {0}
SERVICE_FACTORY_NOT_INSTANCEOF_CLASS_EXCEPTION={0}.getService() returned a service object that is not an instance of the service class {1}
SERVICE_OBJECT_NULL_EXCEPTION={0}.getService() returned a null service object
diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/core/Msg.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/core/Msg.java
index 88506cf20..13dbf6c99 100644
--- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/core/Msg.java
+++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/core/Msg.java
@@ -72,6 +72,7 @@ public class Msg extends NLS {
public static String SERVICE_FACTORY_EXCEPTION;
public static String SERVICE_OBJECT_NULL_EXCEPTION;
+ public static String SERVICE_FACTORY_RECURSION;
public static String STARTLEVEL_EXCEPTION_INVALID_REQUESTED_STARTLEVEL;
public static String STARTLEVEL_CANT_CHANGE_SYSTEMBUNDLE_STARTLEVEL;

Back to the top