langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
changeset 35350 5ec1564e7b1f
parent 35349 4a13a361309a
child 35423 36c7b4ec7a8b
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Jan 20 10:50:28 2016 +0000
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Jan 20 10:53:29 2016 +0000
@@ -42,6 +42,7 @@
 import com.sun.tools.javac.code.Type.*;
 import com.sun.tools.javac.code.TypeMetadata.Annotations;
 import com.sun.tools.javac.code.Types.FunctionDescriptorLookupError;
+import com.sun.tools.javac.comp.ArgumentAttr.LocalCacheContext;
 import com.sun.tools.javac.comp.Check.CheckContext;
 import com.sun.tools.javac.comp.DeferredAttr.AttrMode;
 import com.sun.tools.javac.comp.Infer.FreeTypeListener;
@@ -885,40 +886,46 @@
     }
 
     public void visitClassDef(JCClassDecl tree) {
-        // Local and anonymous classes have not been entered yet, so we need to
-        // do it now.
-        if (env.info.scope.owner.kind.matches(KindSelector.VAL_MTH)) {
-            enter.classEnter(tree, env);
-        } else {
-            // If this class declaration is part of a class level annotation,
-            // as in @MyAnno(new Object() {}) class MyClass {}, enter it in
-            // order to simplify later steps and allow for sensible error
-            // messages.
-            if (env.tree.hasTag(NEWCLASS) && TreeInfo.isInAnnotation(env, tree))
+        Optional<ArgumentAttr.LocalCacheContext> localCacheContext =
+                Optional.ofNullable(env.info.isSpeculative ?
+                        argumentAttr.withLocalCacheContext() : null);
+        try {
+            // Local and anonymous classes have not been entered yet, so we need to
+            // do it now.
+            if (env.info.scope.owner.kind.matches(KindSelector.VAL_MTH)) {
                 enter.classEnter(tree, env);
-        }
-
-        ClassSymbol c = tree.sym;
-        if (c == null) {
-            // exit in case something drastic went wrong during enter.
-            result = null;
-        } else {
-            // make sure class has been completed:
-            c.complete();
-
-            // If this class appears as an anonymous class
-            // in a superclass constructor call where
-            // no explicit outer instance is given,
-            // disable implicit outer instance from being passed.
-            // (This would be an illegal access to "this before super").
-            if (env.info.isSelfCall &&
-                env.tree.hasTag(NEWCLASS) &&
-                ((JCNewClass) env.tree).encl == null)
-            {
-                c.flags_field |= NOOUTERTHIS;
+            } else {
+                // If this class declaration is part of a class level annotation,
+                // as in @MyAnno(new Object() {}) class MyClass {}, enter it in
+                // order to simplify later steps and allow for sensible error
+                // messages.
+                if (env.tree.hasTag(NEWCLASS) && TreeInfo.isInAnnotation(env, tree))
+                    enter.classEnter(tree, env);
             }
-            attribClass(tree.pos(), c);
-            result = tree.type = c.type;
+
+            ClassSymbol c = tree.sym;
+            if (c == null) {
+                // exit in case something drastic went wrong during enter.
+                result = null;
+            } else {
+                // make sure class has been completed:
+                c.complete();
+
+                // If this class appears as an anonymous class
+                // in a superclass constructor call where
+                // no explicit outer instance is given,
+                // disable implicit outer instance from being passed.
+                // (This would be an illegal access to "this before super").
+                if (env.info.isSelfCall &&
+                        env.tree.hasTag(NEWCLASS) &&
+                        ((JCNewClass)env.tree).encl == null) {
+                    c.flags_field |= NOOUTERTHIS;
+                }
+                attribClass(tree.pos(), c);
+                result = tree.type = c.type;
+            }
+        } finally {
+            localCacheContext.ifPresent(LocalCacheContext::leave);
         }
     }