# HG changeset patch # User mcimadamore # Date 1291636237 0 # Node ID 56f59723fddf9622ed7b161e242b876c6ec2aec9 # Parent 5fb14e67c371845b4f73d845cec4cea733e8f465 7002070: If catch clause has an incompatible type, error pointer points to first exception type in list Summary: Attribution should check each component of a disjunctive type separately, rather than checking the corresponding lub() Reviewed-by: jjg diff -r 5fb14e67c371 -r 56f59723fddf src/share/classes/com/sun/tools/javac/comp/Attr.java --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Dec 06 11:49:00 2010 +0000 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Dec 06 11:50:37 2010 +0000 @@ -2889,8 +2889,15 @@ } public void visitTypeDisjunction(JCTypeDisjunction tree) { - List alternatives = attribTypes(tree.alternatives, env); - tree.type = result = check(tree, types.lub(alternatives), TYP, pkind, pt); + ListBuffer multicatchTypes = ListBuffer.lb(); + for (JCExpression typeTree : tree.alternatives) { + Type ctype = attribType(typeTree, env); + ctype = chk.checkType(typeTree.pos(), + chk.checkClassType(typeTree.pos(), ctype), + syms.throwableType); + multicatchTypes.append(ctype); + } + tree.type = result = check(tree, types.lub(multicatchTypes.toList()), TYP, pkind, pt); } public void visitTypeParameter(JCTypeParameter tree) { diff -r 5fb14e67c371 -r 56f59723fddf test/tools/javac/multicatch/Neg06.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/multicatch/Neg06.java Mon Dec 06 11:50:37 2010 +0000 @@ -0,0 +1,16 @@ +/* + * @test /nodynamiccopyright/ + * @bug 7002070 + * + * @summary If catch clause has an incompatible type, error pointer points to first exception type in list + * @author mcimadamore + * @compile/fail/ref=Neg06.out -XDrawDiagnostics Neg06.java + * + */ + +class Neg06 { + void test() { + try { } + catch (String | Integer s) {} + } +} diff -r 5fb14e67c371 -r 56f59723fddf test/tools/javac/multicatch/Neg06.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/multicatch/Neg06.out Mon Dec 06 11:50:37 2010 +0000 @@ -0,0 +1,3 @@ +Neg06.java:14:16: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.String, java.lang.Throwable +Neg06.java:14:25: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.Integer, java.lang.Throwable +2 errors