diff -r a36fce70b505 -r d560276b8a35 src/share/classes/com/sun/tools/javac/comp/Attr.java --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Sep 03 13:20:04 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Sep 10 10:50:59 2014 +0100 @@ -287,7 +287,7 @@ * @param env The current environment. */ boolean isAssignableAsBlankFinal(VarSymbol v, Env env) { - Symbol owner = owner(env); + Symbol owner = env.info.scope.owner; // owner refers to the innermost variable, method or // initializer block declaration at this point. return @@ -302,41 +302,6 @@ ((v.flags() & STATIC) != 0) == Resolve.isStatic(env)); } - /** - * Return the innermost enclosing owner symbol in a given attribution context - */ - Symbol owner(Env env) { - while (true) { - switch (env.tree.getTag()) { - case VARDEF: - //a field can be owner - VarSymbol vsym = ((JCVariableDecl)env.tree).sym; - if (vsym.owner.kind == TYP) { - return vsym; - } - break; - case METHODDEF: - //method def is always an owner - return ((JCMethodDecl)env.tree).sym; - case CLASSDEF: - //class def is always an owner - return ((JCClassDecl)env.tree).sym; - case BLOCK: - //static/instance init blocks are owner - Symbol blockSym = env.info.scope.owner; - if ((blockSym.flags() & BLOCK) != 0) { - return blockSym; - } - break; - case TOPLEVEL: - //toplevel is always an owner (for pkge decls) - return env.info.scope.owner; - } - Assert.checkNonNull(env.next); - env = env.next; - } - } - /** Check that variable can be assigned to. * @param pos The current source code position. * @param v The assigned varaible @@ -3660,7 +3625,7 @@ // and are subject to definite assignment checking. if ((env.info.enclVar == v || v.pos > tree.pos) && v.owner.kind == TYP && - canOwnInitializer(owner(env)) && + enclosingInitEnv(env) != null && v.owner == env.info.scope.owner.enclClass() && ((v.flags() & STATIC) != 0) == Resolve.isStatic(env) && (!env.tree.hasTag(ASSIGN) || @@ -3680,6 +3645,36 @@ } /** + * Returns the enclosing init environment associated with this env (if any). An init env + * can be either a field declaration env or a static/instance initializer env. + */ + Env enclosingInitEnv(Env env) { + while (true) { + switch (env.tree.getTag()) { + case VARDEF: + JCVariableDecl vdecl = (JCVariableDecl)env.tree; + if (vdecl.sym.owner.kind == TYP) { + //field + return env; + } + break; + case BLOCK: + if (env.next.tree.hasTag(CLASSDEF)) { + //instance/static initializer + return env; + } + break; + case METHODDEF: + case CLASSDEF: + case TOPLEVEL: + return null; + } + Assert.checkNonNull(env.next); + env = env.next; + } + } + + /** * Check for illegal references to static members of enum. In * an enum type, constructors and initializers may not * reference its static members unless they are constant. @@ -3732,17 +3727,6 @@ v.name != names._class; } - /** Can the given symbol be the owner of code which forms part - * if class initialization? This is the case if the symbol is - * a type or field, or if the symbol is the synthetic method. - * owning a block. - */ - private boolean canOwnInitializer(Symbol sym) { - return - (sym.kind & (VAR | TYP)) != 0 || - (sym.kind == MTH && (sym.flags() & BLOCK) != 0); - } - Warner noteWarner = new Warner(); /**