--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Tue Mar 29 16:40:07 2011 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Tue Mar 29 16:40:31 2011 +0100
@@ -2901,7 +2901,23 @@
ctype = chk.checkType(typeTree.pos(),
chk.checkClassType(typeTree.pos(), ctype),
syms.throwableType);
- multicatchTypes.append(ctype);
+ if (!ctype.isErroneous()) {
+ //check that alternatives of a disjunctive type are pairwise
+ //unrelated w.r.t. subtyping
+ if (chk.intersects(ctype, multicatchTypes.toList())) {
+ for (Type t : multicatchTypes) {
+ boolean sub = types.isSubtype(ctype, t);
+ boolean sup = types.isSubtype(t, ctype);
+ if (sub || sup) {
+ //assume 'a' <: 'b'
+ Type a = sub ? ctype : t;
+ Type b = sub ? t : ctype;
+ log.error(typeTree.pos(), "multicatch.types.must.be.disjoint", a, b);
+ }
+ }
+ }
+ multicatchTypes.append(ctype);
+ }
}
tree.type = result = check(tree, types.lub(multicatchTypes.toList()), TYP, pkind, pt);
}