JDK-7014734 : Project Coin: Allow optional trailing semicolon to terminate resources list in try-with-resources
  • Type: Bug
  • Component: specification
  • Sub-Component: language
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-01-25
  • Updated: 2017-05-16
  • Resolved: 2011-02-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b130Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
In JSR 334 expert group discussion, forbiding a semicolon to be a terminator of the list of resources when semicolon separates successive resources has been judged an annoyance that could and should be removed.

Comments
SUGGESTED FIX # HG changeset patch # User darcy # Date 1296529592 28800 # Node ID 2ab47c4cd618f731a7d618598d887412110aa001 # Parent 7a75a1803c7af0de9e62fd53adadea18d2912027 7014734: Project Coin: Allow optional trailing semicolon to terminate resources list in try-with-resources Reviewed-by: jjg --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Fri Jan 28 16:54:18 2011 -0800 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Mon Jan 31 19:06:32 2011 -0800 @@ -1639,7 +1639,7 @@ public class JavacParser implements Pars * | WHILE ParExpression Statement * | DO Statement WHILE ParExpression ";" * | TRY Block ( Catches | [Catches] FinallyPart ) - * | TRY "(" ResourceSpecification ")" Block [Catches] [FinallyPart] + * | TRY "(" ResourceSpecification ";"opt ")" Block [Catches] [FinallyPart] * | SWITCH ParExpression "{" SwitchBlockStatementGroups "}" * | SYNCHRONIZED ParExpression Block * | RETURN [Expression] ";" @@ -2182,13 +2182,12 @@ public class JavacParser implements Pars ListBuffer<JCTree> defs = new ListBuffer<JCTree>(); defs.append(resource()); while (S.token() == SEMI) { - // All but last of multiple declarators subsume a semicolon + // All but last of multiple declarators must subsume a semicolon storeEnd(defs.elems.last(), S.endPos()); int semiColonPos = S.pos(); S.nextToken(); - if (S.token() == RPAREN) { // Illegal trailing semicolon + if (S.token() == RPAREN) { // Optional trailing semicolon // after last resource - error(semiColonPos, "try.resource.trailing.semi"); break; } defs.append(resource()); --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Fri Jan 28 16:54:18 2011 -0800 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Mon Jan 31 19:06:32 2011 -0800 @@ -298,9 +298,6 @@ compiler.err.try.resource.may.not.be.ass compiler.err.try.resource.may.not.be.assigned=\ auto-closeable resource {0} may not be assigned -compiler.err.try.resource.trailing.semi=\ - illegal trailing semicolon in resources declaration - # 0: symbol compiler.err.multicatch.parameter.may.not.be.assigned=\ multi-catch parameter {0} may not be assigned --- a/test/tools/javac/TryWithResources/BadTwrSyntax.java Fri Jan 28 16:54:18 2011 -0800 +++ b/test/tools/javac/TryWithResources/BadTwrSyntax.java Mon Jan 31 19:06:32 2011 -0800 @@ -4,13 +4,18 @@ * @author Joseph D. Darcy * @summary Verify bad TWRs don't compile * @compile/fail -source 6 BadTwrSyntax.java - * @compile/fail/ref=BadTwrSyntax.out -XDrawDiagnostics BadTwrSyntax.java + * @compile/fail/ref=BadTwrSyntax.out -XDrawDiagnostics BadTwrSyntax.java */ import java.io.IOException; public class BadTwrSyntax implements AutoCloseable { public static void main(String... args) throws Exception { - // illegal semicolon ending resources + // illegal double semicolon ending resources + try(BadTwr twrflow = new BadTwr();;) { + System.out.println(twrflow.toString()); + } + + // but one semicolon is fine try(BadTwr twrflow = new BadTwr();) { System.out.println(twrflow.toString()); } --- a/test/tools/javac/TryWithResources/BadTwrSyntax.out Fri Jan 28 16:54:18 2011 -0800 +++ b/test/tools/javac/TryWithResources/BadTwrSyntax.out Mon Jan 31 19:06:32 2011 -0800 @@ -1,2 +1,7 @@ BadTwrSyntax.java:14:42: compiler.err.tr -BadTwrSyntax.java:14:42: compiler.err.try.resource.trailing.semi -1 error +BadTwrSyntax.java:14:43: compiler.err.illegal.start.of.type +BadTwrSyntax.java:14:44: compiler.err.expected: = +BadTwrSyntax.java:14:45: compiler.err.expected: ')' +BadTwrSyntax.java:14:47: compiler.err.expected: '{' +BadTwrSyntax.java:15:19: compiler.err.illegal.start.of.expr +BadTwrSyntax.java:15:23: compiler.err.expected: ';' +6 errors --- a/test/tools/javac/diags/examples/TryResourceTrailingSemi.java Fri Jan 28 16:54:18 2011 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -// key: compiler.err.try.resource.trailing.semi - -class TryResoureTrailingSemi implements AutoCloseable { - public static void main(String... args) { - try(TryResoureTrailingSemi r = new TryResoureTrailingSemi();) { - System.out.println(r.toString()); - } - } - - @Override - public void close() {return;} -}
01-02-2011

PUBLIC COMMENTS See http://hg.openjdk.java.net/jdk7/tl/langtools/rev/2ab47c4cd618
01-02-2011

EVALUATION Yes.
25-01-2011