--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Apr 28 08:46:06 2011 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Apr 28 15:05:36 2011 -0700
@@ -2910,6 +2910,7 @@
public void visitTypeUnion(JCTypeUnion tree) {
ListBuffer<Type> multicatchTypes = ListBuffer.lb();
+ ListBuffer<Type> all_multicatchTypes = null; // lazy, only if needed
for (JCExpression typeTree : tree.alternatives) {
Type ctype = attribType(typeTree, env);
ctype = chk.checkType(typeTree.pos(),
@@ -2931,9 +2932,23 @@
}
}
multicatchTypes.append(ctype);
+ if (all_multicatchTypes != null)
+ all_multicatchTypes.append(ctype);
+ } else {
+ if (all_multicatchTypes == null) {
+ all_multicatchTypes = ListBuffer.lb();
+ all_multicatchTypes.appendList(multicatchTypes);
+ }
+ all_multicatchTypes.append(ctype);
}
}
- tree.type = result = check(tree, types.lub(multicatchTypes.toList()), TYP, pkind, pt);
+ Type t = check(tree, types.lub(multicatchTypes.toList()), TYP, pkind, pt);
+ if (t.tag == CLASS) {
+ List<Type> alternatives =
+ ((all_multicatchTypes == null) ? multicatchTypes : all_multicatchTypes).toList();
+ t = new UnionClassType((ClassType) t, alternatives);
+ }
+ tree.type = result = t;
}
public void visitTypeParameter(JCTypeParameter tree) {