Bug 498925: NullPointerException in Config.delegateGetMethodBodies
- fix regressions
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Config.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Config.java
index 93b2dc4..e62e9d6 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Config.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Config.java
@@ -222,8 +222,6 @@
     	            assert(false);
     	            configStack.push(config); // be defensive, put it back
     	        }
-    	        if (configStack.empty())
-    	        	_configs.set(null); // remove entire Stack
     	    }
     	}
 	}
@@ -239,7 +237,7 @@
 		}
     	synchronized (_configs) {
     	    Stack<Config> configStack = _configs.get();
-			if (configStack == null) {
+			if (configStack == null || configStack.isEmpty()) {
 				if (logError)
 					InternalCompilerError.log("Dependencies not configured"); //$NON-NLS-1$
 				return null;
@@ -253,7 +251,7 @@
 			return null;
     	synchronized (_configs) {
     	    Stack<Config> configStack = _configs.get();
-			if (configStack == null)
+			if (configStack == null || configStack.isEmpty())
 				return null;
     	    return configStack.peek();
     	}
@@ -268,6 +266,24 @@
 	    }
 	}
 
+	public static void addToThread(Config config) {
+		if (_configs == null) {
+			InternalCompilerError.log("Dependencies has no _configs"); //$NON-NLS-1$
+			return;
+		}
+    	synchronized (_configs) {
+    	    Stack<Config> configStack = _configs.get();
+			if (configStack != null) {
+				if (!configStack.isEmpty() && configStack.peek() == config)
+					return;
+			} else {
+				configStack = new Stack<>();
+				_configs.set(configStack);
+			}
+			configStack.add(config);
+    	}
+	}
+
 	static boolean getVerifyMethods() {
 		return getConfig().verifyMethods;
 	}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Dependencies.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Dependencies.java
index 94e13ab..082a4bb 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Dependencies.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Dependencies.java
@@ -130,8 +130,10 @@
 			boolean           strictDiet)
     {
     	Config config = Config.configsByClient.get(client);
-    	if (config != null && (config.parser != null || parser == null))
-    		return config;
+    	if (config != null && (config.parser != null || parser == null)) {
+    		Config.addToThread(config);
+			return config;
+		}
     	config = new Config();
     	config.client = new WeakReference<>(client);
     	config.parser = parser;