]> source.dussan.org Git - aspectj.git/commitdiff
210470: preventing weaver leaks: do not mess up the context stack in a multi-threaded...
authoraclement <aclement>
Tue, 27 May 2008 18:46:58 +0000 (18:46 +0000)
committeraclement <aclement>
Tue, 27 May 2008 18:46:58 +0000 (18:46 +0000)
bridge/src/org/aspectj/bridge/context/CompilationAndWeavingContext.java

index 9f546b1316478d99733a74500f69c416c87ae412..c9acc4967d6a6ffce65d198d8144072d4747fb7e 100644 (file)
@@ -136,12 +136,17 @@ public class CompilationAndWeavingContext {
        private CompilationAndWeavingContext() {
        }
        
-       // for testing...
        public static void reset() {
-               contextMap = new HashMap();
-               contextStack = new Stack();
-               formatterMap = new HashMap();
-               nextTokenId = 1;
+        if (!multiThreaded) {
+            contextMap = new HashMap();
+            contextStack = new Stack();
+            formatterMap = new HashMap();
+            nextTokenId = 1;
+        } else {
+            contextMap.remove(Thread.currentThread());
+            // TODO what about formatterMap?
+            // TODO what about nextTokenId?
+        }
        }
        
        public static void setMultiThreaded(boolean mt) { multiThreaded = mt; }
@@ -204,13 +209,12 @@ public class CompilationAndWeavingContext {
                        return contextStack;
                }
                else {
-                       if (contextMap.containsKey(Thread.currentThread())) {
-                               return (Stack) contextMap.get(Thread.currentThread());
-                       } else {
-                               Stack contextStack = new Stack();
+                   Stack contextStack = (Stack) contextMap.get(Thread.currentThread());
+            if (contextStack == null) {
+                               contextStack = new Stack();
                                contextMap.put(Thread.currentThread(),contextStack);
-                               return contextStack;
                        }
+            return contextStack;
                }
        }