--- old/src/share/classes/com/sun/tools/javac/parser/JavacParser.java 2011-01-21 16:43:20.000000000 -0800 +++ new/src/share/classes/com/sun/tools/javac/parser/JavacParser.java 2011-01-21 16:43:20.000000000 -0800 @@ -142,7 +142,7 @@ */ boolean allowAnnotations; - /** Switch: should we recognize automatic resource management? + /** Switch: should we recognize try-with-resources? */ boolean allowTWR; @@ -2181,29 +2181,23 @@ while (S.token() == SEMI) { // All but last of multiple declarators subsume a semicolon storeEnd(defs.elems.last(), S.endPos()); + int semiColonPos = S.pos(); S.nextToken(); + if (S.token() == RPAREN) { // Illegal trailing semicolon + // after last resource + error(semiColonPos, "try.resource.trailing.semi"); + break; + } defs.append(resource()); } return defs.toList(); } - /** Resource = - * VariableModifiers Type VariableDeclaratorId = Expression - * | Expression + /** Resource = VariableModifiers Type VariableDeclaratorId = Expression */ JCTree resource() { - int pos = S.pos(); - if (S.token() == FINAL || S.token() == MONKEYS_AT) { - return variableDeclaratorRest(pos, optFinal(0), parseType(), - ident(), true, null); - } else { - JCExpression t = term(EXPR | TYPE); - if ((lastmode & TYPE) != 0 && S.token() == IDENTIFIER) - return variableDeclaratorRest(pos, toP(F.at(pos).Modifiers(Flags.FINAL)), t, - ident(), true, null); - else - return t; - } + return variableDeclaratorRest(S.pos(), optFinal(Flags.FINAL), + parseType(), ident(), true, null); } /** CompilationUnit = [ { "@" Annotation } PACKAGE Qualident ";"] {ImportDeclaration} {TypeDeclaration}