7179353: try-with-resources fails to compile with generic exception parameters
Reviewed-by: mcimadamore
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java Wed May 29 15:34:56 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java Fri May 31 10:04:59 2013 +0100
@@ -808,9 +808,10 @@
*/
void markThrown(JCTree tree, Type exc) {
if (!chk.isUnchecked(tree.pos(), exc)) {
- if (!chk.isHandled(exc, caught))
+ if (!chk.isHandled(exc, caught)) {
pendingExits.append(new FlowPendingExit(tree, exc));
- thrown = chk.incl(exc, thrown);
+ }
+ thrown = chk.incl(exc, thrown);
}
}
@@ -1066,8 +1067,9 @@
names.close,
List.<Type>nil(),
List.<Type>nil());
+ Type mt = types.memberType(resource.type, closeMethod);
if (closeMethod.kind == MTH) {
- for (Type t : ((MethodSymbol)closeMethod).getThrownTypes()) {
+ for (Type t : mt.getThrownTypes()) {
markThrown(resource, t);
}
}
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java Wed May 29 15:34:56 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java Fri May 31 10:04:59 2013 +0100
@@ -349,7 +349,7 @@
: isAccessible(env, t.tsym, checkInner);
}
- /** Is symbol accessible as a member of given type in given evironment?
+ /** Is symbol accessible as a member of given type in given environment?
* @param env The current environment.
* @param site The type of which the tested symbol is regarded
* as a member.
@@ -490,11 +490,11 @@
};
/** Try to instantiate the type of a method so that it fits
- * given type arguments and argument types. If succesful, return
+ * given type arguments and argument types. If successful, return
* the method's instantiated type, else return null.
* The instantiation will take into account an additional leading
* formal parameter if the method is an instance method seen as a member
- * of un underdetermined site In this case, we treat site as an additional
+ * of an under determined site. In this case, we treat site as an additional
* parameter and the parameters of the class containing the method as
* additional type variables that get instantiated.
*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T7179353/GenericsAndTWRCompileErrorTest.java Fri May 31 10:04:59 2013 +0100
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2013, 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 7179353
+ * @summary try-with-resources fails to compile with generic exception parameters
+ * @compile GenericsAndTWRCompileErrorTest.java
+ */
+
+public class GenericsAndTWRCompileErrorTest {
+
+ public static class Resource<E extends Exception> implements AutoCloseable {
+ public void close() throws E { }
+ }
+
+ public <E extends Exception> void test() throws E {
+ try (Resource<E> r = new Resource<E>()) {
+
+ }
+ }
+}