Bug 304859 - Uninjection order is incorrect when a new value is set after the object has been constructed
diff --git a/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/internal/context/Computation.java b/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/internal/context/Computation.java
index 2116716..7d912b5 100644
--- a/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/internal/context/Computation.java
+++ b/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/internal/context/Computation.java
@@ -97,14 +97,16 @@
 	/**
 	 * Remove this computation from all contexts that are tracking it
 	 */
-	protected void removeAll() {
+	protected void removeAll(EclipseContext originatingContext) {
 		for (Iterator it = dependencies.keySet().iterator(); it.hasNext();) {
 			((EclipseContext) it.next()).listeners.remove(this);
 		}
 		dependencies.clear();
+		// Bug 304859
+		originatingContext.listeners.remove(this);
 	}
 
-	void startListening() {
+	void startListening(EclipseContext originatingContext) {
 		if (EclipseContext.DEBUG)
 			System.out.println(toString() + " now listening to: " //$NON-NLS-1$
 					+ mapToString(dependencies));
@@ -131,6 +133,9 @@
 			} else
 				c.listeners.add(this);
 		}
+		// Bug 304859
+		if (!dependencies.containsKey(originatingContext))
+			originatingContext.listeners.remove(this);
 	}
 
 	protected void stopListening(IEclipseContext context, String name) {
@@ -145,7 +150,8 @@
 		if (properties != null) {
 			if (EclipseContext.DEBUG)
 				System.out.println(toString() + " no longer listening to " + context + "," + name); //$NON-NLS-1$
-			((EclipseContext) context).listeners.remove(this); // XXX
+			// Bug 304859 - causes reordering of listeners
+			// ((EclipseContext) context).listeners.remove(this); // XXX
 			// IEclipseContext
 			properties.remove(name);
 			// if we no longer track any values in the context, remove dependency
diff --git a/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/internal/context/EclipseContext.java b/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/internal/context/EclipseContext.java
index 50df977..88815fe 100644
--- a/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/internal/context/EclipseContext.java
+++ b/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/internal/context/EclipseContext.java
@@ -154,10 +154,11 @@
 			} finally {
 				currentComputation.set(oldComputation);
 			}
+			EclipseContext eventsContext = (EclipseContext) ((ObjectProviderContext) event.getContext()).getContext();
 			if (result)
-				startListening();
+				startListening(eventsContext);
 			else
-				removeAll();
+				removeAll(eventsContext);
 			return result;
 		}
 
diff --git a/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/internal/context/ValueComputation.java b/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/internal/context/ValueComputation.java
index 634fbe5..fff5c1a 100644
--- a/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/internal/context/ValueComputation.java
+++ b/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/internal/context/ValueComputation.java
@@ -115,7 +115,7 @@
 			IObjectProvider provider = event.getContext();
 			IEclipseContext eventsContext = ((ObjectProviderContext) provider).getContext();
 			if (originatingContext.equals(eventsContext)) {
-				removeAll();
+				removeAll(originatingContext);
 				return;
 			}
 		}
@@ -145,7 +145,7 @@
 			EclipseContext.currentComputation.set(oldComputation); // XXX
 			// IEclipseContext
 		}
-		startListening();
+		startListening(originatingContext);
 		return cachedValue;
 	}