--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java Mon Nov 17 23:11:05 2014 -0800
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java Wed Nov 19 13:46:04 2014 +0100
@@ -2562,6 +2562,8 @@
* This pass implements the last step of the dataflow analysis, namely
* the effectively-final analysis check. This checks that every local variable
* reference from a lambda body/local inner class is either final or effectively final.
+ * Additional this also checks that every variable that is used as an operand to
+ * try-with-resources is final or effectively final.
* As effectively final variables are marked as such during DA/DU, this pass must run after
* AssignAnalyzer.
*/
@@ -2690,6 +2692,18 @@
}
}
+ public void visitTry(JCTry tree) {
+ for (JCTree resource : tree.resources) {
+ if (!resource.hasTag(VARDEF)) {
+ Symbol var = TreeInfo.symbol(resource);
+ if (var != null && (var.flags() & (FINAL | EFFECTIVELY_FINAL)) == 0) {
+ log.error(resource.pos(), "try.with.resources.expr.effectively.final.var", var);
+ }
+ }
+ }
+ super.visitTry(tree);
+ }
+
/**************************************************************************
* main method
*************************************************************************/