--- old/src/share/classes/com/sun/tools/javac/comp/Attr.java 2010-06-30 14:15:13.000000000 -0700 +++ new/src/share/classes/com/sun/tools/javac/comp/Attr.java 2010-06-30 14:15:13.000000000 -0700 @@ -244,7 +244,11 @@ !((base == null || (base.getTag() == JCTree.IDENT && TreeInfo.name(base) == names._this)) && isAssignableAsBlankFinal(v, env)))) { - log.error(pos, "cant.assign.val.to.final.var", v); + if (types.asSuper(v.type, syms.autoCloseableType.tsym) != null) { //ARM resource + log.error(pos, "arm.resource.may.not.be.assigned", v); + } else { + log.error(pos, "cant.assign.val.to.final.var", v); + } } } @@ -981,14 +985,33 @@ } public void visitTry(JCTry tree) { + // Create a new local environment with a local scope. + Env localEnv = env.dup(tree, env.info.dup(env.info.scope.dup())); + // Attribute resource declarations + ListBuffer resourceVars = ListBuffer.lb(); + for (JCTree resource : tree.resources) { + attribExpr(resource, localEnv); + chk.checkArmResource(resource); + if (resource.getTag() == JCTree.VARDEF) { + VarSymbol var = (VarSymbol)TreeInfo.symbolFor(resource); + var.setData(ElementKind.RESOURCE_VARIABLE); + resourceVars.append(var); + } + } // Attribute body - attribStat(tree.body, env.dup(tree, env.info.dup())); + attribStat(tree.body, localEnv.dup(tree, localEnv.info.dup())); + + //remove arm resource vars from local scope - such variables cannot be + //accessed from catch/finally clauses + for (VarSymbol resourceVar : resourceVars) { + localEnv.info.scope.remove(resourceVar); + } // Attribute catch clauses for (List l = tree.catchers; l.nonEmpty(); l = l.tail) { JCCatch c = l.head; Env catchEnv = - env.dup(c, env.info.dup(env.info.scope.dup())); + localEnv.dup(c, localEnv.info.dup(localEnv.info.scope.dup())); Type ctype = attribStat(c.param, catchEnv); if (TreeInfo.isMultiCatch(c)) { //check that multi-catch parameter is marked as final @@ -1008,7 +1031,9 @@ } // Attribute finalizer - if (tree.finalizer != null) attribStat(tree.finalizer, env); + if (tree.finalizer != null) attribStat(tree.finalizer, localEnv); + + localEnv.info.scope.leave(); result = null; }