aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian de Alwis2013-08-28 16:04:31 (EDT)
committerGerrit Code Review @ Eclipse.org2013-08-31 00:16:57 (EDT)
commit4267133345c2161d0948faaacd9a051d74564c78 (patch)
treed135a73de294278cbf781b473a6267a243080e39
parent0124f3fbd7dde7a9b9249f66cebade70fbe67496 (diff)
downloadeclipse.platform.runtime-4267133345c2161d0948faaacd9a051d74564c78.zip
eclipse.platform.runtime-4267133345c2161d0948faaacd9a051d74564c78.tar.gz
eclipse.platform.runtime-4267133345c2161d0948faaacd9a051d74564c78.tar.bz2
Bug 411147 - ServiceLocator#getService(Class) may register an invalid service object; IEclipseContext#get(Class) does not handle NOT_A_VALUEI20130903-0900I20130903-0800I20130902-2000I20130901-2000I20130831-1500I20130830-2000refs/changes/50/15950/2
-rw-r--r--bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/IContextFunction.java3
-rw-r--r--bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/EclipseContext.java16
-rw-r--r--tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/EclipseContextTest.java4
3 files changed, 18 insertions, 5 deletions
diff --git a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/IContextFunction.java b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/IContextFunction.java
index 4a4f0c8..e10d32d 100644
--- a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/IContextFunction.java
+++ b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/IContextFunction.java
@@ -67,7 +67,8 @@ public interface IContextFunction {
* @param contextKey
* The context key used to find this function; may be {@code null} such
* as if invoked directly.
- * @return The concrete value.
+ * @return The concrete value. Implementations may return {@link org.eclipse.e4.core.di.IInjector#NOT_A_VALUE}
+ * to cause lookup to continue up the context hierarchy.
*/
public Object compute(IEclipseContext context, String contextKey);
diff --git a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/EclipseContext.java b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/EclipseContext.java
index 5552533..6203a16 100644
--- a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/EclipseContext.java
+++ b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/EclipseContext.java
@@ -217,8 +217,12 @@ public class EclipseContext implements IEclipseContext {
public Object internalGet(EclipseContext originatingContext, String name, boolean local) {
if (this == originatingContext) {
ValueComputation valueComputation = localValueComputations.get(name);
- if (valueComputation != null)
- return valueComputation.get();
+ if (valueComputation != null) {
+ Object result = valueComputation.get();
+ if (result != IInjector.NOT_A_VALUE) {
+ return result;
+ }
+ }
}
Object result = null;
@@ -670,8 +674,12 @@ public class EclipseContext implements IEclipseContext {
Map<String, Object> result = new HashMap<String, Object>(localValueComputations.size());
for (String string : localValueComputations.keySet()) {
ValueComputation vc = localValueComputations.get(string);
- if (vc != null)
- result.put(string, vc.get());
+ if (vc != null) {
+ Object r = vc.get();
+ if (r != IInjector.NOT_A_VALUE) {
+ result.put(string, vc.get());
+ }
+ }
}
return result;
}
diff --git a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/EclipseContextTest.java b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/EclipseContextTest.java
index 1423f4c..21e186a 100644
--- a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/EclipseContextTest.java
+++ b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/EclipseContextTest.java
@@ -330,6 +330,10 @@ public class EclipseContextTest extends TestCase {
}
});
+ // must call several times as the underlying ValueComputation wrapper is
+ // created on the first time, but re-used for subsequent calls.
+ assertNull(context.get("x"));
+ assertNull(context.get("x"));
assertNull(context.get("x"));
context.dispose();
}