7002070: If catch clause has an incompatible type, error pointer points to first exception type in list

Mon, 06 Dec 2010 11:50:37 +0000

author
mcimadamore
date
Mon, 06 Dec 2010 11:50:37 +0000
changeset 774
56f59723fddf
parent 773
5fb14e67c371
child 775
536ee9f126b1

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

src/share/classes/com/sun/tools/javac/comp/Attr.java file | annotate | diff | comparison | revisions
test/tools/javac/multicatch/Neg06.java file | annotate | diff | comparison | revisions
test/tools/javac/multicatch/Neg06.out file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Dec 06 11:49:00 2010 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Dec 06 11:50:37 2010 +0000
     1.3 @@ -2889,8 +2889,15 @@
     1.4      }
     1.5  
     1.6      public void visitTypeDisjunction(JCTypeDisjunction tree) {
     1.7 -        List<Type> alternatives = attribTypes(tree.alternatives, env);
     1.8 -        tree.type = result = check(tree, types.lub(alternatives), TYP, pkind, pt);
     1.9 +        ListBuffer<Type> multicatchTypes = ListBuffer.lb();
    1.10 +        for (JCExpression typeTree : tree.alternatives) {
    1.11 +            Type ctype = attribType(typeTree, env);
    1.12 +            ctype = chk.checkType(typeTree.pos(),
    1.13 +                          chk.checkClassType(typeTree.pos(), ctype),
    1.14 +                          syms.throwableType);
    1.15 +            multicatchTypes.append(ctype);
    1.16 +        }
    1.17 +        tree.type = result = check(tree, types.lub(multicatchTypes.toList()), TYP, pkind, pt);
    1.18      }
    1.19  
    1.20      public void visitTypeParameter(JCTypeParameter tree) {
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/multicatch/Neg06.java	Mon Dec 06 11:50:37 2010 +0000
     2.3 @@ -0,0 +1,16 @@
     2.4 +/*
     2.5 + * @test /nodynamiccopyright/
     2.6 + * @bug 7002070
     2.7 + *
     2.8 + * @summary If catch clause has an incompatible type, error pointer points to first exception type in list
     2.9 + * @author mcimadamore
    2.10 + * @compile/fail/ref=Neg06.out -XDrawDiagnostics Neg06.java
    2.11 + *
    2.12 + */
    2.13 +
    2.14 +class Neg06 {
    2.15 +    void test() {
    2.16 +        try { }
    2.17 +        catch (String | Integer s) {}
    2.18 +    }
    2.19 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/multicatch/Neg06.out	Mon Dec 06 11:50:37 2010 +0000
     3.3 @@ -0,0 +1,3 @@
     3.4 +Neg06.java:14:16: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.String, java.lang.Throwable
     3.5 +Neg06.java:14:25: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.Integer, java.lang.Throwable
     3.6 +2 errors

mercurial