8163027: AssertionError while compiling a program that uses try with resources.
authorsadayapalam
Wed, 21 Sep 2016 05:26:26 +0530
changeset 41156 251471aec877
parent 41155 93dad90c22c1
child 41157 b235a429089a
8163027: AssertionError while compiling a program that uses try with resources. Reviewed-by: vromero
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java
langtools/test/tools/javac/TryWithResources/TwrAndTypeVariables2Test.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Sep 20 12:12:18 2016 +0530
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Sep 21 05:26:26 2016 +0530
@@ -1451,7 +1451,7 @@
             try {
                 close = rs.resolveQualifiedMethod(pos,
                         env,
-                        resource,
+                        types.skipTypeVars(resource, false),
                         names.close,
                         List.<Type>nil(),
                         List.<Type>nil());
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java	Tue Sep 20 12:12:18 2016 +0530
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java	Wed Sep 21 05:26:26 2016 +0530
@@ -1098,7 +1098,7 @@
                     if (types.asSuper(sup, syms.autoCloseableType.tsym) != null) {
                         Symbol closeMethod = rs.resolveQualifiedMethod(tree,
                                 attrEnv,
-                                sup,
+                                types.skipTypeVars(sup, false),
                                 names.close,
                                 List.<Type>nil(),
                                 List.<Type>nil());
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/TryWithResources/TwrAndTypeVariables2Test.java	Wed Sep 21 05:26:26 2016 +0530
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2016, 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 8163027
+ * @summary AssertionError while compiling program that uses try with resources
+ * @compile TwrAndTypeVariables2Test.java
+ */
+
+abstract class TwrAndTypeVariables2Test_01 implements AutoCloseable {
+    @Override
+    public void close() {
+    }
+    public boolean close(long timeout) {
+        return true;
+    }
+}
+
+public abstract class TwrAndTypeVariables2Test<C extends TwrAndTypeVariables2Test_01> {
+    abstract C newCloseable();
+
+    void m() throws Exception{
+        try(C p= newCloseable()){
+        }
+    }
+}