7013420: Project Coin: remove general expression support from try-with-resources statement

Tue, 25 Jan 2011 17:02:56 -0800

author
darcy
date
Tue, 25 Jan 2011 17:02:56 -0800
changeset 840
7f8794f9cc14
parent 839
a8437c34fdc7
child 841
df371fd16386

7013420: Project Coin: remove general expression support from try-with-resources statement
Reviewed-by: mcimadamore, jjg

src/share/classes/com/sun/tools/javac/parser/JavacParser.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/resources/compiler.properties file | annotate | diff | comparison | revisions
test/tools/javac/TryWithResources/BadTwrSyntax.out file | annotate | diff | comparison | revisions
test/tools/javac/TryWithResources/DuplicateResource.java file | annotate | diff | comparison | revisions
test/tools/javac/TryWithResources/ExplicitFinal.java file | annotate | diff | comparison | revisions
test/tools/javac/TryWithResources/ImplicitFinal.java file | annotate | diff | comparison | revisions
test/tools/javac/TryWithResources/ImplicitFinal.out file | annotate | diff | comparison | revisions
test/tools/javac/TryWithResources/TwrFlow.java file | annotate | diff | comparison | revisions
test/tools/javac/TryWithResources/TwrFlow.out file | annotate | diff | comparison | revisions
test/tools/javac/TryWithResources/TwrInference.java file | annotate | diff | comparison | revisions
test/tools/javac/TryWithResources/TwrIntersection.java file | annotate | diff | comparison | revisions
test/tools/javac/TryWithResources/TwrIntersection02.java file | annotate | diff | comparison | revisions
test/tools/javac/TryWithResources/TwrIntersection02.out file | annotate | diff | comparison | revisions
test/tools/javac/TryWithResources/TwrMultiCatch.java file | annotate | diff | comparison | revisions
test/tools/javac/TryWithResources/TwrOnNonResource.java file | annotate | diff | comparison | revisions
test/tools/javac/TryWithResources/TwrOnNonResource.out file | annotate | diff | comparison | revisions
test/tools/javac/diags/examples/TryResourceTrailingSemi.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Mon Jan 24 16:38:56 2011 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Tue Jan 25 17:02:56 2011 -0800
     1.3 @@ -142,7 +142,7 @@
     1.4       */
     1.5      boolean allowAnnotations;
     1.6  
     1.7 -    /** Switch: should we recognize automatic resource management?
     1.8 +    /** Switch: should we recognize try-with-resources?
     1.9       */
    1.10      boolean allowTWR;
    1.11  
    1.12 @@ -2184,29 +2184,23 @@
    1.13          while (S.token() == SEMI) {
    1.14              // All but last of multiple declarators subsume a semicolon
    1.15              storeEnd(defs.elems.last(), S.endPos());
    1.16 +            int semiColonPos = S.pos();
    1.17              S.nextToken();
    1.18 +            if (S.token() == RPAREN) { // Illegal trailing semicolon
    1.19 +                                       // after last resource
    1.20 +                error(semiColonPos, "try.resource.trailing.semi");
    1.21 +                break;
    1.22 +            }
    1.23              defs.append(resource());
    1.24          }
    1.25          return defs.toList();
    1.26      }
    1.27  
    1.28 -    /** Resource =
    1.29 -     *    VariableModifiers Type VariableDeclaratorId = Expression
    1.30 -     *  | Expression
    1.31 +    /** Resource = VariableModifiersOpt Type VariableDeclaratorId = Expression
    1.32       */
    1.33      JCTree resource() {
    1.34 -        int pos = S.pos();
    1.35 -        if (S.token() == FINAL || S.token() == MONKEYS_AT) {
    1.36 -            return variableDeclaratorRest(pos, optFinal(0), parseType(),
    1.37 -                                          ident(), true, null);
    1.38 -        } else {
    1.39 -            JCExpression t = term(EXPR | TYPE);
    1.40 -            if ((lastmode & TYPE) != 0 && S.token() == IDENTIFIER)
    1.41 -                return variableDeclaratorRest(pos, toP(F.at(pos).Modifiers(Flags.FINAL)), t,
    1.42 -                                              ident(), true, null);
    1.43 -            else
    1.44 -                return t;
    1.45 -        }
    1.46 +        return variableDeclaratorRest(S.pos(), optFinal(Flags.FINAL),
    1.47 +                                      parseType(), ident(), true, null);
    1.48      }
    1.49  
    1.50      /** CompilationUnit = [ { "@" Annotation } PACKAGE Qualident ";"] {ImportDeclaration} {TypeDeclaration}
     2.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Mon Jan 24 16:38:56 2011 -0800
     2.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Jan 25 17:02:56 2011 -0800
     2.3 @@ -177,6 +177,8 @@
     2.4      final parameter {0} may not be assigned
     2.5  compiler.err.try.resource.may.not.be.assigned=\
     2.6      auto-closeable resource {0} may not be assigned
     2.7 +compiler.err.try.resource.trailing.semi=\
     2.8 +    illegal trailing semicolon in resources declaration
     2.9  compiler.err.multicatch.parameter.may.not.be.assigned=\
    2.10      multi-catch parameter {0} may not be assigned
    2.11  compiler.err.finally.without.try=\
     3.1 --- a/test/tools/javac/TryWithResources/BadTwrSyntax.out	Mon Jan 24 16:38:56 2011 -0800
     3.2 +++ b/test/tools/javac/TryWithResources/BadTwrSyntax.out	Tue Jan 25 17:02:56 2011 -0800
     3.3 @@ -1,2 +1,2 @@
     3.4 -BadTwrSyntax.java:14:43: compiler.err.illegal.start.of.expr
     3.5 +BadTwrSyntax.java:14:42: compiler.err.try.resource.trailing.semi
     3.6  1 error
     4.1 --- a/test/tools/javac/TryWithResources/DuplicateResource.java	Mon Jan 24 16:38:56 2011 -0800
     4.2 +++ b/test/tools/javac/TryWithResources/DuplicateResource.java	Tue Jan 25 17:02:56 2011 -0800
     4.3 @@ -1,5 +1,5 @@
     4.4  /*
     4.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
     4.6 + * Copyright (c) 2010, 2011 Oracle and/or its affiliates. All rights reserved.
     4.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.8   *
     4.9   * This code is free software; you can redistribute it and/or modify it
    4.10 @@ -23,9 +23,9 @@
    4.11  
    4.12  /*
    4.13   * @test
    4.14 - * @bug 6911256 6964740 6965277
    4.15 + * @bug 6911256 6964740 6965277 7013420
    4.16   * @author Maurizio Cimadamore
    4.17 - * @summary Check that lowered arm block does not end up creating resource twice
    4.18 + * @summary Check that lowered try-with-resources block does not end up creating resource twice
    4.19   */
    4.20  
    4.21  import java.util.ArrayList;
    4.22 @@ -45,7 +45,7 @@
    4.23      static ArrayList<TestResource> resources = new ArrayList<TestResource>();
    4.24  
    4.25      public static void main(String[] args) {
    4.26 -        try(new TestResource()) {
    4.27 +        try(TestResource tr = new TestResource()) {
    4.28             //do something
    4.29          } catch (Exception e) {
    4.30              throw new AssertionError("Shouldn't reach here", e);
    4.31 @@ -59,7 +59,7 @@
    4.32         }
    4.33         TestResource resource = resources.get(0);
    4.34         if (!resource.isClosed) {
    4.35 -           throw new AssertionError("Resource used in ARM block has not been automatically closed");
    4.36 +           throw new AssertionError("Resource used in try-with-resources block has not been automatically closed");
    4.37         }
    4.38      }
    4.39  }
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/tools/javac/TryWithResources/ExplicitFinal.java	Tue Jan 25 17:02:56 2011 -0800
     5.3 @@ -0,0 +1,56 @@
     5.4 +/*
     5.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 + *
     5.8 + * This code is free software; you can redistribute it and/or modify it
     5.9 + * under the terms of the GNU General Public License version 2 only, as
    5.10 + * published by the Free Software Foundation.
    5.11 + *
    5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.15 + * version 2 for more details (a copy is included in the LICENSE file that
    5.16 + * accompanied this code).
    5.17 + *
    5.18 + * You should have received a copy of the GNU General Public License version
    5.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.21 + *
    5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    5.23 + * or visit www.oracle.com if you need additional information or have any
    5.24 + * questions.
    5.25 + */
    5.26 +
    5.27 +/*
    5.28 + * @test
    5.29 + * @bug 7013420
    5.30 + * @author Joseph D. Darcy
    5.31 + * @summary Test that resource variables are accepted as explicitly final.
    5.32 + */
    5.33 +
    5.34 +import java.io.IOException;
    5.35 +
    5.36 +public class ExplicitFinal implements AutoCloseable {
    5.37 +    public static void main(String... args) {
    5.38 +        try(final ExplicitFinal r2 = new ExplicitFinal()) {
    5.39 +            r2.toString();
    5.40 +        } catch (IOException ioe) {
    5.41 +            throw new AssertionError("Shouldn't reach here", ioe);
    5.42 +        }
    5.43 +
    5.44 +        try(final @SuppressWarnings("unchecked") ExplicitFinal r3 = new ExplicitFinal()) {
    5.45 +            r3.toString();
    5.46 +        } catch (IOException ioe) {
    5.47 +            throw new AssertionError("Shouldn't reach here", ioe);
    5.48 +        }
    5.49 +
    5.50 +        try(@SuppressWarnings("unchecked") ExplicitFinal r4 = new ExplicitFinal()) {
    5.51 +            r4.toString();
    5.52 +        } catch (IOException ioe) {
    5.53 +            throw new AssertionError("Shouldn't reach here", ioe);
    5.54 +        }
    5.55 +    }
    5.56 +    public void close() throws IOException {
    5.57 +        System.out.println("Calling close on " + this);
    5.58 +    }
    5.59 +}
     6.1 --- a/test/tools/javac/TryWithResources/ImplicitFinal.java	Mon Jan 24 16:38:56 2011 -0800
     6.2 +++ b/test/tools/javac/TryWithResources/ImplicitFinal.java	Tue Jan 25 17:02:56 2011 -0800
     6.3 @@ -1,6 +1,6 @@
     6.4  /*
     6.5   * @test  /nodynamiccopyright/
     6.6 - * @bug 6911256 6964740 6965277
     6.7 + * @bug 6911256 6964740 6965277 7013420
     6.8   * @author Maurizio Cimadamore
     6.9   * @summary Test that resource variables are implicitly final
    6.10   * @compile/fail/ref=ImplicitFinal.out -XDrawDiagnostics ImplicitFinal.java
    6.11 @@ -15,12 +15,25 @@
    6.12          } catch (IOException ioe) { // Not reachable
    6.13              throw new AssertionError("Shouldn't reach here", ioe);
    6.14          }
    6.15 +
    6.16 +        try(@SuppressWarnings("unchecked") ImplicitFinal r1 = new ImplicitFinal()) {
    6.17 +            r1 = null; //disallowed
    6.18 +        } catch (IOException ioe) { // Not reachable
    6.19 +            throw new AssertionError("Shouldn't reach here", ioe);
    6.20 +        }
    6.21 +
    6.22 +        try(final ImplicitFinal r2 = new ImplicitFinal()) {
    6.23 +            r2 = null; //disallowed
    6.24 +        } catch (IOException ioe) { // Not reachable
    6.25 +            throw new AssertionError("Shouldn't reach here", ioe);
    6.26 +        }
    6.27 +
    6.28 +        try(final @SuppressWarnings("unchecked") ImplicitFinal r3 = new ImplicitFinal()) {
    6.29 +            r3 = null; //disallowed
    6.30 +        } catch (IOException ioe) { // Not reachable
    6.31 +            throw new AssertionError("Shouldn't reach here", ioe);
    6.32 +        }
    6.33      }
    6.34 -
    6.35 -
    6.36 -     // A close method, but the class is <em>not</em> Closeable or
    6.37 -     // AutoCloseable.
    6.38 -
    6.39      public void close() throws IOException {
    6.40          throw new IOException();
    6.41      }
     7.1 --- a/test/tools/javac/TryWithResources/ImplicitFinal.out	Mon Jan 24 16:38:56 2011 -0800
     7.2 +++ b/test/tools/javac/TryWithResources/ImplicitFinal.out	Tue Jan 25 17:02:56 2011 -0800
     7.3 @@ -1,2 +1,5 @@
     7.4  ImplicitFinal.java:14:13: compiler.err.try.resource.may.not.be.assigned: r
     7.5 -1 error
     7.6 +ImplicitFinal.java:20:13: compiler.err.try.resource.may.not.be.assigned: r1
     7.7 +ImplicitFinal.java:26:13: compiler.err.try.resource.may.not.be.assigned: r2
     7.8 +ImplicitFinal.java:32:13: compiler.err.try.resource.may.not.be.assigned: r3
     7.9 +4 errors
     8.1 --- a/test/tools/javac/TryWithResources/TwrFlow.java	Mon Jan 24 16:38:56 2011 -0800
     8.2 +++ b/test/tools/javac/TryWithResources/TwrFlow.java	Tue Jan 25 17:02:56 2011 -0800
     8.3 @@ -1,26 +1,16 @@
     8.4  /*
     8.5   * @test  /nodynamiccopyright/
     8.6 - * @bug 6911256 6964740
     8.7 + * @bug 6911256 6964740 7013420
     8.8   * @author Joseph D. Darcy
     8.9 - * @summary Test exception analysis of ARM blocks
    8.10 + * @summary Test exception analysis of try-with-resources blocks
    8.11   * @compile/fail/ref=TwrFlow.out -XDrawDiagnostics TwrFlow.java
    8.12   */
    8.13  
    8.14  import java.io.IOException;
    8.15  public class TwrFlow implements AutoCloseable {
    8.16      public static void main(String... args) {
    8.17 -        try(TwrFlow armflow = new TwrFlow()) {
    8.18 -            System.out.println(armflow.toString());
    8.19 -        } catch (IOException ioe) { // Not reachable
    8.20 -            throw new AssertionError("Shouldn't reach here", ioe);
    8.21 -        }
    8.22 -        // CustomCloseException should be caught or added to throws clause
    8.23 -
    8.24 -        // Also check behavior on a resource expression rather than a
    8.25 -        // declaration.
    8.26 -        TwrFlow armflowexpr = new TwrFlow();
    8.27 -        try(armflowexpr) {
    8.28 -            System.out.println(armflowexpr.toString());
    8.29 +        try(TwrFlow twrFlow = new TwrFlow()) {
    8.30 +            System.out.println(twrFlow.toString());
    8.31          } catch (IOException ioe) { // Not reachable
    8.32              throw new AssertionError("Shouldn't reach here", ioe);
    8.33          }
     9.1 --- a/test/tools/javac/TryWithResources/TwrFlow.out	Mon Jan 24 16:38:56 2011 -0800
     9.2 +++ b/test/tools/javac/TryWithResources/TwrFlow.out	Tue Jan 25 17:02:56 2011 -0800
     9.3 @@ -1,5 +1,3 @@
     9.4  TwrFlow.java:14:11: compiler.err.except.never.thrown.in.try: java.io.IOException
     9.5 -TwrFlow.java:24:11: compiler.err.except.never.thrown.in.try: java.io.IOException
     9.6  TwrFlow.java:12:46: compiler.err.unreported.exception.need.to.catch.or.throw: CustomCloseException
     9.7 -TwrFlow.java:22:26: compiler.err.unreported.exception.need.to.catch.or.throw: CustomCloseException
     9.8 -4 errors
     9.9 +2 errors
    10.1 --- a/test/tools/javac/TryWithResources/TwrInference.java	Mon Jan 24 16:38:56 2011 -0800
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,43 +0,0 @@
    10.4 -/*
    10.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    10.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    10.7 - *
    10.8 - * This code is free software; you can redistribute it and/or modify it
    10.9 - * under the terms of the GNU General Public License version 2 only, as
   10.10 - * published by the Free Software Foundation.
   10.11 - *
   10.12 - * This code is distributed in the hope that it will be useful, but WITHOUT
   10.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   10.14 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   10.15 - * version 2 for more details (a copy is included in the LICENSE file that
   10.16 - * accompanied this code).
   10.17 - *
   10.18 - * You should have received a copy of the GNU General Public License version
   10.19 - * 2 along with this work; if not, write to the Free Software Foundation,
   10.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   10.21 - *
   10.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   10.23 - * or visit www.oracle.com if you need additional information or have any
   10.24 - * questions.
   10.25 - */
   10.26 -
   10.27 -/*
   10.28 - * @test
   10.29 - * @bug 6911256 6964740 6965277
   10.30 - * @author Maurizio Cimadamore
   10.31 - * @summary Verify that method type-inference works as expected in TWR context
   10.32 - * @compile TwrInference.java
   10.33 - */
   10.34 -
   10.35 -class TwrInference {
   10.36 -
   10.37 -    public void test() {
   10.38 -        try(getX()) {
   10.39 -            //do something
   10.40 -        } catch (Exception e) { // Not reachable
   10.41 -            throw new AssertionError("Shouldn't reach here", e);
   10.42 -        }
   10.43 -    }
   10.44 -
   10.45 -    <X> X getX() { return null; }
   10.46 -}
    11.1 --- a/test/tools/javac/TryWithResources/TwrIntersection.java	Mon Jan 24 16:38:56 2011 -0800
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,47 +0,0 @@
    11.4 -/*
    11.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    11.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    11.7 - *
    11.8 - * This code is free software; you can redistribute it and/or modify it
    11.9 - * under the terms of the GNU General Public License version 2 only, as
   11.10 - * published by the Free Software Foundation.
   11.11 - *
   11.12 - * This code is distributed in the hope that it will be useful, but WITHOUT
   11.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   11.14 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   11.15 - * version 2 for more details (a copy is included in the LICENSE file that
   11.16 - * accompanied this code).
   11.17 - *
   11.18 - * You should have received a copy of the GNU General Public License version
   11.19 - * 2 along with this work; if not, write to the Free Software Foundation,
   11.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   11.21 - *
   11.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   11.23 - * or visit www.oracle.com if you need additional information or have any
   11.24 - * questions.
   11.25 - */
   11.26 -
   11.27 -/*
   11.28 - * @test
   11.29 - * @bug 6911256 6964740 6965277
   11.30 - * @author Maurizio Cimadamore
   11.31 - * @summary Resource of an intersection type crashes Flow
   11.32 - * @compile TwrIntersection.java
   11.33 - */
   11.34 -
   11.35 -interface MyCloseable extends AutoCloseable {
   11.36 -   void close() throws java.io.IOException;
   11.37 -}
   11.38 -
   11.39 -class ResourceTypeVar {
   11.40 -
   11.41 -    public void test() {
   11.42 -        try(getX()) {
   11.43 -            //do something
   11.44 -        } catch (java.io.IOException e) { // Not reachable
   11.45 -            throw new AssertionError("Shouldn't reach here", e);
   11.46 -        }
   11.47 -    }
   11.48 -
   11.49 -    <X extends Number & MyCloseable> X getX() { return null; }
   11.50 -}
    12.1 --- a/test/tools/javac/TryWithResources/TwrIntersection02.java	Mon Jan 24 16:38:56 2011 -0800
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,37 +0,0 @@
    12.4 -/*
    12.5 - * @test  /nodynamiccopyright/
    12.6 - * @bug 6911256 6964740 6965277
    12.7 - * @author Maurizio Cimadamore
    12.8 - * @summary Check that resources of an intersection type forces union of exception types
    12.9 - *          to be caught outside twr block
   12.10 - * @compile/fail/ref=TwrIntersection02.out -XDrawDiagnostics TwrIntersection02.java
   12.11 - */
   12.12 -
   12.13 -class TwrIntersection02 {
   12.14 -
   12.15 -    static class Exception1 extends Exception {}
   12.16 -    static class Exception2 extends Exception {}
   12.17 -
   12.18 -
   12.19 -    interface MyResource1 extends AutoCloseable {
   12.20 -       void close() throws Exception1;
   12.21 -    }
   12.22 -
   12.23 -    interface MyResource2 extends AutoCloseable {
   12.24 -       void close() throws Exception2;
   12.25 -    }
   12.26 -
   12.27 -    public void test1() throws Exception1 {
   12.28 -        try(getX()) {
   12.29 -            //do something
   12.30 -        }
   12.31 -    }
   12.32 -
   12.33 -    public void test2() throws Exception2 {
   12.34 -        try(getX()) {
   12.35 -            //do something
   12.36 -        }
   12.37 -    }
   12.38 -
   12.39 -    <X extends MyResource1 & MyResource2> X getX() { return null; }
   12.40 -}
    13.1 --- a/test/tools/javac/TryWithResources/TwrIntersection02.out	Mon Jan 24 16:38:56 2011 -0800
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,3 +0,0 @@
    13.4 -TwrIntersection02.java:25:21: compiler.err.unreported.exception.need.to.catch.or.throw: TwrIntersection02.Exception2
    13.5 -TwrIntersection02.java:31:21: compiler.err.unreported.exception.need.to.catch.or.throw: TwrIntersection02.Exception1
    13.6 -2 errors
    14.1 --- a/test/tools/javac/TryWithResources/TwrMultiCatch.java	Mon Jan 24 16:38:56 2011 -0800
    14.2 +++ b/test/tools/javac/TryWithResources/TwrMultiCatch.java	Tue Jan 25 17:02:56 2011 -0800
    14.3 @@ -1,5 +1,5 @@
    14.4  /*
    14.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    14.6 + * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
    14.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    14.8   *
    14.9   * This code is free software; you can redistribute it and/or modify it
   14.10 @@ -23,7 +23,7 @@
   14.11  
   14.12  /*
   14.13   * @test
   14.14 - * @bug 6911256 6964740
   14.15 + * @bug 6911256 6964740 7013420
   14.16   * @author Joseph D. Darcy
   14.17   * @summary Test that TWR and multi-catch play well together
   14.18   * @compile TwrMultiCatch.java
   14.19 @@ -48,9 +48,9 @@
   14.20  
   14.21      private static void test(TwrMultiCatch twrMultiCatch,
   14.22                       Class<? extends Exception> expected) {
   14.23 -        try(twrMultiCatch) {
   14.24 -            System.out.println(twrMultiCatch.toString());
   14.25 -        } catch (final CustomCloseException1 |
   14.26 +        try(TwrMultiCatch tmc = twrMultiCatch) {
   14.27 +            System.out.println(tmc.toString());
   14.28 +        } catch (CustomCloseException1 |
   14.29                   CustomCloseException2 exception) {
   14.30              if (!exception.getClass().equals(expected) ) {
   14.31                  throw new RuntimeException("Unexpected catch!");
   14.32 @@ -68,7 +68,7 @@
   14.33  
   14.34          try {
   14.35              throw t;
   14.36 -        } catch (final CustomCloseException1 |
   14.37 +        } catch (CustomCloseException1 |
   14.38                   CustomCloseException2 exception) {
   14.39              throw exception;
   14.40          } catch (Throwable throwable) {
    15.1 --- a/test/tools/javac/TryWithResources/TwrOnNonResource.java	Mon Jan 24 16:38:56 2011 -0800
    15.2 +++ b/test/tools/javac/TryWithResources/TwrOnNonResource.java	Tue Jan 25 17:02:56 2011 -0800
    15.3 @@ -1,6 +1,6 @@
    15.4  /*
    15.5   * @test  /nodynamiccopyright/
    15.6 - * @bug 6911256 6964740
    15.7 + * @bug 6911256 6964740 7013420
    15.8   * @author Joseph D. Darcy
    15.9   * @summary Verify invalid TWR block is not accepted.
   15.10   * @compile/fail -source 6 TwrOnNonResource.java
   15.11 @@ -18,18 +18,6 @@
   15.12          try(TwrOnNonResource aonr = new TwrOnNonResource()) {
   15.13              System.out.println(aonr.toString());
   15.14          } catch (Exception e) {;}
   15.15 -
   15.16 -        // Also check expression form
   15.17 -        TwrOnNonResource aonr = new TwrOnNonResource();
   15.18 -        try(aonr) {
   15.19 -            System.out.println(aonr.toString());
   15.20 -        }
   15.21 -        try(aonr) {
   15.22 -            System.out.println(aonr.toString());
   15.23 -        } finally {;}
   15.24 -        try(aonr) {
   15.25 -            System.out.println(aonr.toString());
   15.26 -        } catch (Exception e) {;}
   15.27      }
   15.28  
   15.29      /*
    16.1 --- a/test/tools/javac/TryWithResources/TwrOnNonResource.out	Mon Jan 24 16:38:56 2011 -0800
    16.2 +++ b/test/tools/javac/TryWithResources/TwrOnNonResource.out	Tue Jan 25 17:02:56 2011 -0800
    16.3 @@ -1,7 +1,4 @@
    16.4  TwrOnNonResource.java:12:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
    16.5  TwrOnNonResource.java:15:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
    16.6  TwrOnNonResource.java:18:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
    16.7 -TwrOnNonResource.java:24:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
    16.8 -TwrOnNonResource.java:27:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
    16.9 -TwrOnNonResource.java:30:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
   16.10 -6 errors
   16.11 +3 errors
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/test/tools/javac/diags/examples/TryResourceTrailingSemi.java	Tue Jan 25 17:02:56 2011 -0800
    17.3 @@ -0,0 +1,35 @@
    17.4 +/*
    17.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
    17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    17.7 + *
    17.8 + * This code is free software; you can redistribute it and/or modify it
    17.9 + * under the terms of the GNU General Public License version 2 only, as
   17.10 + * published by the Free Software Foundation.
   17.11 + *
   17.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   17.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   17.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   17.15 + * version 2 for more details (a copy is included in the LICENSE file that
   17.16 + * accompanied this code).
   17.17 + *
   17.18 + * You should have received a copy of the GNU General Public License version
   17.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   17.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   17.21 + *
   17.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   17.23 + * or visit www.oracle.com if you need additional information or have any
   17.24 + * questions.
   17.25 + */
   17.26 +
   17.27 +// key: compiler.err.try.resource.trailing.semi
   17.28 +
   17.29 +class TryResoureTrailingSemi implements AutoCloseable {
   17.30 +    public static void main(String... args) {
   17.31 +        try(TryResoureTrailingSemi r = new TryResoureTrailingSemi();) {
   17.32 +            System.out.println(r.toString());
   17.33 +        }
   17.34 +    }
   17.35 +
   17.36 +    @Override
   17.37 +    public void close() {return;}
   17.38 +}

mercurial