src/share/classes/com/sun/tools/javac/parser/JavacParser.java

Print this page

        

@@ -140,11 +140,11 @@
 
     /** Switch: should we recognize annotations?
      */
     boolean allowAnnotations;
 
-    /** Switch: should we recognize automatic resource management?
+    /** Switch: should we recognize try-with-resources?
      */
     boolean allowTWR;
 
     /** Switch: should we keep docComments?
      */

@@ -2179,33 +2179,27 @@
         ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
         defs.append(resource());
         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}
      */
     public JCTree.JCCompilationUnit parseCompilationUnit() {