--- old/test/tools/javac/TryWithResources/T7022711.java 2015-10-14 09:44:24.403473465 +0300 +++ new/test/tools/javac/TryWithResources/T7022711.java 2015-10-14 09:44:24.339473463 +0300 @@ -9,10 +9,20 @@ class T7022711 { public static void main (String args[]) throws Exception { + // declared resource try (DataInputStream is = new DataInputStream(new FileInputStream("x"))) { while (true) { is.getChar(); // method not found } + } catch (EOFException e) { + } + + // resource as variable + DataInputStream is = new DataInputStream(new FileInputStream("x")); + try (is) { + while (true) { + is.getChar(); // method not found + } } catch (EOFException e) { } } --- old/test/tools/javac/TryWithResources/T7022711.out 2015-10-14 09:44:24.627473472 +0300 +++ new/test/tools/javac/TryWithResources/T7022711.out 2015-10-14 09:44:24.559473470 +0300 @@ -1,2 +1,3 @@ -T7022711.java:14:19: compiler.err.cant.resolve.location.args: kindname.method, getChar, , , (compiler.misc.location.1: kindname.variable, is, java.io.DataInputStream) -1 error +T7022711.java:15:19: compiler.err.cant.resolve.location.args: kindname.method, getChar, , , (compiler.misc.location.1: kindname.variable, is, java.io.DataInputStream) +T7022711.java:24:19: compiler.err.cant.resolve.location.args: kindname.method, getChar, , , (compiler.misc.location.1: kindname.variable, is, java.io.DataInputStream) +2 errors --- old/test/tools/javac/TryWithResources/T7032633.java 2015-10-14 09:44:24.851473478 +0300 +++ new/test/tools/javac/TryWithResources/T7032633.java 2015-10-14 09:44:24.779473476 +0300 @@ -33,8 +33,15 @@ public class T7032633 { void test() throws IOException { + // declared resource try (OutputStream out = System.out) { out.flush(); } + + // resource as variable + OutputStream out = System.out; + try (out) { + out.flush(); + } } } --- old/test/tools/javac/TryWithResources/TwrForVariable1.java 2015-10-14 09:44:25.075473485 +0300 +++ new/test/tools/javac/TryWithResources/TwrForVariable1.java 2015-10-14 09:44:25.003473483 +0300 @@ -37,6 +37,18 @@ } assertCloseCount(6); + + // null test cases + TwrForVariable1 n = null; + + try (n) { + } + try (n) { + throw new Exception(); + } catch (Exception e) { + } + + assertCloseCount(6); } static void assertCloseCount(int expectedCloseCount) { --- old/test/tools/javac/TryWithResources/TwrForVariable2.java 2015-10-14 09:44:25.307473492 +0300 +++ new/test/tools/javac/TryWithResources/TwrForVariable2.java 2015-10-14 09:44:25.235473490 +0300 @@ -27,6 +27,9 @@ try (args.length == 0 ? v : v) { fail("general expressions not allowed"); } + try ((TwrForVariable2)null) { + fail("null as variable is not allowed"); + } } static void fail(String reason) { --- old/test/tools/javac/TryWithResources/TwrForVariable2.out 2015-10-14 09:44:25.531473499 +0300 +++ new/test/tools/javac/TryWithResources/TwrForVariable2.out 2015-10-14 09:44:25.459473496 +0300 @@ -4,4 +4,5 @@ TwrForVariable2.java:21:14: compiler.err.try.with.resources.expr.needs.var TwrForVariable2.java:24:16: compiler.err.try.with.resources.expr.needs.var TwrForVariable2.java:27:31: compiler.err.try.with.resources.expr.needs.var -6 errors +TwrForVariable2.java:30:14: compiler.err.try.with.resources.expr.needs.var +7 errors --- old/test/tools/javac/TryWithResources/TwrForVariable3.java 2015-10-14 09:44:25.755473505 +0300 +++ new/test/tools/javac/TryWithResources/TwrForVariable3.java 2015-10-14 09:44:25.687473503 +0300 @@ -7,9 +7,16 @@ public static void main(String... args) { TwrForVariable3 v1 = new TwrForVariable3(); Object v2 = new Object(); + Object v3 = new Object() { + public void close() { + } + }; try (v2) { - fail("no an AutoCloseable"); + fail("not an AutoCloseable"); + } + try (v3) { + fail("not an AutoCloseable although has close() method"); } try (java.lang.Object) { fail("not a variable access"); --- old/test/tools/javac/TryWithResources/TwrForVariable3.out 2015-10-14 09:44:25.983473512 +0300 +++ new/test/tools/javac/TryWithResources/TwrForVariable3.out 2015-10-14 09:44:25.911473510 +0300 @@ -1,4 +1,5 @@ -TwrForVariable3.java:11:14: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type: (compiler.misc.inconvertible.types: java.lang.Object, java.lang.AutoCloseable)) -TwrForVariable3.java:14:18: compiler.err.cant.resolve.location: kindname.class, lang, , , (compiler.misc.location: kindname.package, java, null) -TwrForVariable3.java:17:14: compiler.err.cant.resolve.location: kindname.variable, java, , , (compiler.misc.location: kindname.class, TwrForVariable3, null) -3 errors +TwrForVariable3.java:15:14: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type: (compiler.misc.inconvertible.types: java.lang.Object, java.lang.AutoCloseable)) +TwrForVariable3.java:18:14: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type: (compiler.misc.inconvertible.types: java.lang.Object, java.lang.AutoCloseable)) +TwrForVariable3.java:21:18: compiler.err.cant.resolve.location: kindname.class, lang, , , (compiler.misc.location: kindname.package, java, null) +TwrForVariable3.java:24:14: compiler.err.cant.resolve.location: kindname.variable, java, , , (compiler.misc.location: kindname.class, TwrForVariable3, null) +4 errors --- /dev/null 2015-08-31 00:12:54.703509796 +0300 +++ new/test/tools/javac/TryWithResources/ResourceVariableOutsideTry.java 2015-10-14 09:44:26.131473516 +0300 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015, 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. + */ + +/* + * @test + * @bug 7196163 + * @summary Resource variable could be acessible from try, catch and finally blocks + * @compile ResourceVariableOutsideTry.java + */ + +public class ResourceVariableOutsideTry { + void test() { + MyResource c = new MyResource(); + + try(c) { + c.test(); + } catch (Exception e) { + c.test(); + } finally { + c.test(); + } + } + + static class MyResource implements AutoCloseable { + public void close() throws Exception {} + void test() {} + } +} --- /dev/null 2015-08-31 00:12:54.703509796 +0300 +++ new/test/tools/javac/TryWithResources/TwrAndAnonymousClass.java 2015-10-14 09:44:26.327473522 +0300 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2015, 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. + */ + +/* + * @test + * @bug 7196163 + * @summary Twr with resource variables declared as anonymous class instance + * @compile TwrAndAnonymousClass.java + */ + +public class TwrAndAnonymousClass { + + public static void main(String... args) { + + AutoCloseable r = new AutoCloseable() { + public void close() { }; + }; + + try (r) { + } catch (Exception e) {} + + try (AutoCloseable r1 = new AutoCloseable() { public void close() { }; };) { + } catch (Exception e) {} + } +} --- /dev/null 2015-08-31 00:12:54.703509796 +0300 +++ new/test/tools/javac/TryWithResources/TwrAndGenerics.java 2015-10-14 09:44:26.523473528 +0300 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015, 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. + */ + +/* + * @test + * @bug 7196163 + * @summary Twr with resource variables of parametrized types + * @compile TwrAndGenerics.java + */ + +public class TwrAndGenerics { + + public static + void copy(S s, T t) throws Exception { + try (s; t;) { + } + } +} --- /dev/null 2015-08-31 00:12:54.703509796 +0300 +++ new/test/tools/javac/TryWithResources/TwrAndLambda.java 2015-10-14 09:44:26.719473534 +0300 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, 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. + */ + +/* + * @test + * @bug 7196163 + * @summary Twr with resource variables as lambda expressions and method references + * @compile TwrAndLambda.java + */ + +public class TwrAndLambda { + + public static void main(String... args) { + + // Lambda expression + AutoCloseable v1 = () -> {}; + // Static method reference + AutoCloseable v2 = TwrAndLambda::close1; + // Instance method reference + AutoCloseable v3 = new TwrAndLambda()::close2; + + try (v1) { + } catch(Exception e) {} + try (v2) { + } catch(Exception e) {} + try (v3) { + } catch(Exception e) {} + } + + public static void close1() throws Exception { } + + public void close2() throws Exception { } +} --- /dev/null 2015-08-31 00:12:54.703509796 +0300 +++ new/test/tools/javac/TryWithResources/TwrVarAndDecl.java 2015-10-14 09:44:26.911473540 +0300 @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2015, 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. + */ + +/* + * @test + * @bug 7196163 + * @summary Variable and direct declaration both in one twr block + */ + +public class TwrVarAndDecl implements AutoCloseable { + + public static void main(String... args) { + TwrVarAndDecl r = new TwrVarAndDecl(); + + try (r; TwrVarAndDecl r2 = new TwrVarAndDecl();) { + } + } + + public void close() {} +} --- /dev/null 2015-08-31 00:12:54.703509796 +0300 +++ new/test/tools/javac/TryWithResources/TwrVarKinds.java 2015-10-14 09:44:27.111473545 +0300 @@ -0,0 +1,50 @@ +/* + * @test /nodynamiccopyright/ + * @bug 7196163 + * @summary Twr with different kinds of variables: local, instance, class, parameter + * @compile/fail/ref=TwrVarKinds.out -XDrawDiagnostics TwrVarKinds.java + */ + +public class TwrVarKinds implements AutoCloseable { + + final static TwrVarKinds r1 = new TwrVarKinds(); + final TwrVarKinds r2 = new TwrVarKinds(); + static TwrVarKinds r3 = new TwrVarKinds(); + TwrVarKinds r4 = new TwrVarKinds(); + + public static void main(String... args) { + + TwrVarKinds r5 = new TwrVarKinds(); + + /* static final field - ok */ + try (r1) { + } + + /* non-static final field - ok */ + try (r1.r2) { + } + + /* static non-final field - wrong */ + try (r3) { + } + + /* non-static non-final field -wrong */ + try (r1.r4) { + } + + /* local variable - ok */ + try (r5) { + } + + /* parameter - ok */ + method(r5); + } + + static void method(TwrVarKinds r) { + /* parameter */ + try (r) { + } + } + + public void close() {} +} --- /dev/null 2015-08-31 00:12:54.703509796 +0300 +++ new/test/tools/javac/TryWithResources/TwrVarKinds.out 2015-10-14 09:44:27.315473552 +0300 @@ -0,0 +1,3 @@ +TwrVarKinds.java:28:14: compiler.err.try.with.resources.expr.effectively.final.var: r3 +TwrVarKinds.java:32:16: compiler.err.try.with.resources.expr.effectively.final.var: r4 +2 errors --- /dev/null 2015-08-31 00:12:54.703509796 +0300 +++ new/test/tools/javac/TryWithResources/TwrVarRedeclaration.java 2015-10-14 09:44:27.507473557 +0300 @@ -0,0 +1,28 @@ +/* + * @test /nodynamiccopyright/ + * @bug 7196163 + * @summary Variable redeclaration inside twr block + * @compile/fail/ref=TwrVarRedeclaration.out -XDrawDiagnostics TwrVarRedeclaration.java + */ + +public class TwrVarRedeclaration implements AutoCloseable { + + public static void main(String... args) { + TwrVarRedeclaration r = new TwrVarRedeclaration(); + + try (r) { + TwrVarRedeclaration r = new TwrVarRedeclaration(); + } + + try (r) { + Object r = new Object(); + } + + try (r) { + } catch (Exception e) { + Exception r = new Exception(); + } + } + + public void close() {} +} --- /dev/null 2015-08-31 00:12:54.703509796 +0300 +++ new/test/tools/javac/TryWithResources/TwrVarRedeclaration.out 2015-10-14 09:44:27.707473563 +0300 @@ -0,0 +1,4 @@ +TwrVarRedeclaration.java:14:33: compiler.err.already.defined: kindname.variable, r, kindname.method, main(java.lang.String...) +TwrVarRedeclaration.java:18:20: compiler.err.already.defined: kindname.variable, r, kindname.method, main(java.lang.String...) +TwrVarRedeclaration.java:23:23: compiler.err.already.defined: kindname.variable, r, kindname.method, main(java.lang.String...) +3 errors --- /dev/null 2015-08-31 00:12:54.703509796 +0300 +++ new/test/tools/javac/TryWithResources/WeirdTwr_WithVar.java 2015-10-14 09:44:27.891473569 +0300 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015, 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. + */ + +/* + * @test + * @bug 7196163 6911256 6964740 + * @summary Strange TWRs with resource variables + */ + +public class WeirdTwr_WithVar implements AutoCloseable { + private static int closeCount = 0; + + public static void main(String... args) { + WeirdTwr_WithVar r1 = new WeirdTwr_WithVar(); + + try (r1; WeirdTwr_WithVar r2 = r1;) { + if (r1 != r2) + throw new RuntimeException("Unexpected inequality."); + } + + if (closeCount != 2) + throw new RuntimeException("Bad closeCount " + closeCount); + } + + public void close() { + closeCount++; + } +} --- /dev/null 2015-08-31 00:12:54.703509796 +0300 +++ new/test/tools/javac/defaultMethods/private/PrivateGenerics.java 2015-10-14 09:44:28.087473574 +0300 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2015, 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. + */ + +/* + * @test + * @bug 8071453 + * @summary Verify that generics work with private method in interface + */ + +public class PrivateGenerics { + + interface I { + private T foo() { return null; }; + default void m(T t) { + T t1 = t; + T t2 = foo(); + } + } + + interface J { + private M foo() { return null; } + default void m(N n) { + N n1 = n; + N n2 = foo(); + } + } + + public static void main(String[] args) { + I i = new I<>() {}; + i.m("string"); + String s = i.foo(); + + J j = new J() {}; + j.m("string"); + s = j.foo(); + } +}