8006732: support correct bytecode storage of type annotations in multicatch

Wed, 23 Oct 2013 23:20:32 -0400

author
emc
date
Wed, 23 Oct 2013 23:20:32 -0400
changeset 2167
d2fa3f7e964e
parent 2166
31fe30e2deac
child 2168
119747cd9f25

8006732: support correct bytecode storage of type annotations in multicatch
Summary: Fix issue with annotations being added before attribution, which causes multicatch not to work right and several tests to fail.
Reviewed-by: jfranck, jjg

src/share/classes/com/sun/tools/javac/comp/Attr.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/MemberEnter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/jvm/Gen.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.out file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/newlocations/MultiCatch.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/referenceinfos/MultiCatch.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Oct 23 15:45:18 2013 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Oct 23 23:20:32 2013 -0400
     1.3 @@ -4096,8 +4096,9 @@
     1.4      }
     1.5  
     1.6      private static List<Attribute.TypeCompound> fromAnnotations(List<JCAnnotation> annotations) {
     1.7 -        if (annotations.isEmpty())
     1.8 +        if (annotations.isEmpty()) {
     1.9              return List.nil();
    1.10 +        }
    1.11  
    1.12          ListBuffer<Attribute.TypeCompound> buf = new ListBuffer<>();
    1.13          for (JCAnnotation anno : annotations) {
    1.14 @@ -4109,6 +4110,10 @@
    1.15                  // Any better solutions?
    1.16                  buf.append((Attribute.TypeCompound) anno.attribute);
    1.17              }
    1.18 +            // Eventually we will want to throw an exception here, but
    1.19 +            // we can't do that just yet, because it gets triggered
    1.20 +            // when attempting to attach an annotation that isn't
    1.21 +            // defined.
    1.22          }
    1.23          return buf.toList();
    1.24      }
     2.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Wed Oct 23 15:45:18 2013 -0700
     2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Wed Oct 23 23:20:32 2013 -0400
     2.3 @@ -573,45 +573,51 @@
     2.4  
     2.5          Env<AttrContext> localEnv = methodEnv(tree, env);
     2.6  
     2.7 -        DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos());
     2.8 +        annotate.enterStart();
     2.9          try {
    2.10 -            // Compute the method type
    2.11 -            m.type = signature(m, tree.typarams, tree.params,
    2.12 -                               tree.restype, tree.recvparam,
    2.13 -                               tree.thrown,
    2.14 -                               localEnv);
    2.15 +            DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos());
    2.16 +            try {
    2.17 +                // Compute the method type
    2.18 +                m.type = signature(m, tree.typarams, tree.params,
    2.19 +                                   tree.restype, tree.recvparam,
    2.20 +                                   tree.thrown,
    2.21 +                                   localEnv);
    2.22 +            } finally {
    2.23 +                deferredLintHandler.setPos(prevLintPos);
    2.24 +            }
    2.25 +
    2.26 +            if (types.isSignaturePolymorphic(m)) {
    2.27 +                m.flags_field |= SIGNATURE_POLYMORPHIC;
    2.28 +            }
    2.29 +
    2.30 +            // Set m.params
    2.31 +            ListBuffer<VarSymbol> params = new ListBuffer<VarSymbol>();
    2.32 +            JCVariableDecl lastParam = null;
    2.33 +            for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
    2.34 +                JCVariableDecl param = lastParam = l.head;
    2.35 +                params.append(Assert.checkNonNull(param.sym));
    2.36 +            }
    2.37 +            m.params = params.toList();
    2.38 +
    2.39 +            // mark the method varargs, if necessary
    2.40 +            if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0)
    2.41 +                m.flags_field |= Flags.VARARGS;
    2.42 +
    2.43 +            localEnv.info.scope.leave();
    2.44 +            if (chk.checkUnique(tree.pos(), m, enclScope)) {
    2.45 +            enclScope.enter(m);
    2.46 +            }
    2.47 +
    2.48 +            annotateLater(tree.mods.annotations, localEnv, m, tree.pos());
    2.49 +            // Visit the signature of the method. Note that
    2.50 +            // TypeAnnotate doesn't descend into the body.
    2.51 +            typeAnnotate(tree, localEnv, m, tree.pos());
    2.52 +
    2.53 +            if (tree.defaultValue != null)
    2.54 +                annotateDefaultValueLater(tree.defaultValue, localEnv, m);
    2.55          } finally {
    2.56 -            deferredLintHandler.setPos(prevLintPos);
    2.57 +            annotate.enterDone();
    2.58          }
    2.59 -
    2.60 -        if (types.isSignaturePolymorphic(m)) {
    2.61 -            m.flags_field |= SIGNATURE_POLYMORPHIC;
    2.62 -        }
    2.63 -
    2.64 -        // Set m.params
    2.65 -        ListBuffer<VarSymbol> params = new ListBuffer<VarSymbol>();
    2.66 -        JCVariableDecl lastParam = null;
    2.67 -        for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
    2.68 -            JCVariableDecl param = lastParam = l.head;
    2.69 -            params.append(Assert.checkNonNull(param.sym));
    2.70 -        }
    2.71 -        m.params = params.toList();
    2.72 -
    2.73 -        // mark the method varargs, if necessary
    2.74 -        if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0)
    2.75 -            m.flags_field |= Flags.VARARGS;
    2.76 -
    2.77 -        localEnv.info.scope.leave();
    2.78 -        if (chk.checkUnique(tree.pos(), m, enclScope)) {
    2.79 -            enclScope.enter(m);
    2.80 -        }
    2.81 -        annotateLater(tree.mods.annotations, localEnv, m, tree.pos());
    2.82 -        // Visit the signature of the method. Note that
    2.83 -        // TypeAnnotate doesn't descend into the body.
    2.84 -        typeAnnotate(tree, localEnv, m, tree.pos());
    2.85 -
    2.86 -        if (tree.defaultValue != null)
    2.87 -            annotateDefaultValueLater(tree.defaultValue, localEnv, m);
    2.88      }
    2.89  
    2.90      /** Create a fresh environment for method bodies.
    2.91 @@ -639,61 +645,68 @@
    2.92              localEnv.info.staticLevel++;
    2.93          }
    2.94          DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos());
    2.95 +        annotate.enterStart();
    2.96          try {
    2.97 -            if (TreeInfo.isEnumInit(tree)) {
    2.98 -                attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype);
    2.99 -            } else {
   2.100 -                attr.attribType(tree.vartype, localEnv);
   2.101 -                if (tree.nameexpr != null) {
   2.102 -                    attr.attribExpr(tree.nameexpr, localEnv);
   2.103 -                    MethodSymbol m = localEnv.enclMethod.sym;
   2.104 -                    if (m.isConstructor()) {
   2.105 -                        Type outertype = m.owner.owner.type;
   2.106 -                        if (outertype.hasTag(TypeTag.CLASS)) {
   2.107 -                            checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type");
   2.108 -                            checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name");
   2.109 +            try {
   2.110 +                if (TreeInfo.isEnumInit(tree)) {
   2.111 +                    attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype);
   2.112 +                } else {
   2.113 +                    attr.attribType(tree.vartype, localEnv);
   2.114 +                    if (tree.nameexpr != null) {
   2.115 +                        attr.attribExpr(tree.nameexpr, localEnv);
   2.116 +                        MethodSymbol m = localEnv.enclMethod.sym;
   2.117 +                        if (m.isConstructor()) {
   2.118 +                            Type outertype = m.owner.owner.type;
   2.119 +                            if (outertype.hasTag(TypeTag.CLASS)) {
   2.120 +                                checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type");
   2.121 +                                checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name");
   2.122 +                            } else {
   2.123 +                                log.error(tree, "receiver.parameter.not.applicable.constructor.toplevel.class");
   2.124 +                            }
   2.125                          } else {
   2.126 -                            log.error(tree, "receiver.parameter.not.applicable.constructor.toplevel.class");
   2.127 +                            checkType(tree.vartype, m.owner.type, "incorrect.receiver.type");
   2.128 +                            checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name");
   2.129                          }
   2.130 -                    } else {
   2.131 -                        checkType(tree.vartype, m.owner.type, "incorrect.receiver.type");
   2.132 -                        checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name");
   2.133                      }
   2.134                  }
   2.135 +            } finally {
   2.136 +                deferredLintHandler.setPos(prevLintPos);
   2.137              }
   2.138 +
   2.139 +            if ((tree.mods.flags & VARARGS) != 0) {
   2.140 +                //if we are entering a varargs parameter, we need to
   2.141 +                //replace its type (a plain array type) with the more
   2.142 +                //precise VarargsType --- we need to do it this way
   2.143 +                //because varargs is represented in the tree as a
   2.144 +                //modifier on the parameter declaration, and not as a
   2.145 +                //distinct type of array node.
   2.146 +                ArrayType atype = (ArrayType)tree.vartype.type.unannotatedType();
   2.147 +                tree.vartype.type = atype.makeVarargs();
   2.148 +            }
   2.149 +            Scope enclScope = enter.enterScope(env);
   2.150 +            VarSymbol v =
   2.151 +                new VarSymbol(0, tree.name, tree.vartype.type, enclScope.owner);
   2.152 +            v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree);
   2.153 +            tree.sym = v;
   2.154 +            if (tree.init != null) {
   2.155 +                v.flags_field |= HASINIT;
   2.156 +                if ((v.flags_field & FINAL) != 0 &&
   2.157 +                    needsLazyConstValue(tree.init)) {
   2.158 +                    Env<AttrContext> initEnv = getInitEnv(tree, env);
   2.159 +                    initEnv.info.enclVar = v;
   2.160 +                    v.setLazyConstValue(initEnv(tree, initEnv), attr, tree);
   2.161 +                }
   2.162 +            }
   2.163 +            if (chk.checkUnique(tree.pos(), v, enclScope)) {
   2.164 +                chk.checkTransparentVar(tree.pos(), v, enclScope);
   2.165 +                enclScope.enter(v);
   2.166 +            }
   2.167 +            annotateLater(tree.mods.annotations, localEnv, v, tree.pos());
   2.168 +            typeAnnotate(tree.vartype, env, v, tree.pos());
   2.169 +            v.pos = tree.pos;
   2.170          } finally {
   2.171 -            deferredLintHandler.setPos(prevLintPos);
   2.172 +            annotate.enterDone();
   2.173          }
   2.174 -
   2.175 -        if ((tree.mods.flags & VARARGS) != 0) {
   2.176 -            //if we are entering a varargs parameter, we need to replace its type
   2.177 -            //(a plain array type) with the more precise VarargsType --- we need
   2.178 -            //to do it this way because varargs is represented in the tree as a modifier
   2.179 -            //on the parameter declaration, and not as a distinct type of array node.
   2.180 -            ArrayType atype = (ArrayType)tree.vartype.type.unannotatedType();
   2.181 -            tree.vartype.type = atype.makeVarargs();
   2.182 -        }
   2.183 -        Scope enclScope = enter.enterScope(env);
   2.184 -        VarSymbol v =
   2.185 -            new VarSymbol(0, tree.name, tree.vartype.type, enclScope.owner);
   2.186 -        v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree);
   2.187 -        tree.sym = v;
   2.188 -        if (tree.init != null) {
   2.189 -            v.flags_field |= HASINIT;
   2.190 -            if ((v.flags_field & FINAL) != 0 &&
   2.191 -                needsLazyConstValue(tree.init)) {
   2.192 -                Env<AttrContext> initEnv = getInitEnv(tree, env);
   2.193 -                initEnv.info.enclVar = v;
   2.194 -                v.setLazyConstValue(initEnv(tree, initEnv), attr, tree);
   2.195 -            }
   2.196 -        }
   2.197 -        if (chk.checkUnique(tree.pos(), v, enclScope)) {
   2.198 -            chk.checkTransparentVar(tree.pos(), v, enclScope);
   2.199 -            enclScope.enter(v);
   2.200 -        }
   2.201 -        annotateLater(tree.mods.annotations, localEnv, v, tree.pos());
   2.202 -        typeAnnotate(tree.vartype, env, v, tree.pos());
   2.203 -        v.pos = tree.pos;
   2.204      }
   2.205      // where
   2.206      void checkType(JCTree tree, Type type, String diag) {
     3.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Wed Oct 23 15:45:18 2013 -0700
     3.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Wed Oct 23 23:20:32 2013 -0400
     3.3 @@ -1652,9 +1652,10 @@
     3.4                                        startpc,  end, code.curCP(),
     3.5                                        catchType);
     3.6                          if (subCatch.type.isAnnotated()) {
     3.7 -                            // All compounds share the same position, simply update the
     3.8 -                            // first one.
     3.9 -                            subCatch.type.getAnnotationMirrors().head.position.type_index = catchType;
    3.10 +                            for (Attribute.TypeCompound tc :
    3.11 +                                     subCatch.type.getAnnotationMirrors()) {
    3.12 +                                tc.position.type_index = catchType;
    3.13 +                            }
    3.14                          }
    3.15                      }
    3.16                      gaps = gaps.tail;
    3.17 @@ -1668,9 +1669,10 @@
    3.18                                        startpc, endpc, code.curCP(),
    3.19                                        catchType);
    3.20                          if (subCatch.type.isAnnotated()) {
    3.21 -                            // All compounds share the same position, simply update the
    3.22 -                            // first one.
    3.23 -                            subCatch.type.getAnnotationMirrors().head.position.type_index = catchType;
    3.24 +                            for (Attribute.TypeCompound tc :
    3.25 +                                     subCatch.type.getAnnotationMirrors()) {
    3.26 +                                tc.position.type_index = catchType;
    3.27 +                            }
    3.28                          }
    3.29                      }
    3.30                  }
     4.1 --- a/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.java	Wed Oct 23 15:45:18 2013 -0700
     4.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.java	Wed Oct 23 23:20:32 2013 -0400
     4.3 @@ -3,7 +3,6 @@
     4.4   * @bug 8006733 8006775
     4.5   * @summary Ensure behavior for nested types is correct.
     4.6   * @author Werner Dietl
     4.7 - * @ignore
     4.8   * @compile/fail/ref=CantAnnotateStaticClass2.out -XDrawDiagnostics CantAnnotateStaticClass2.java
     4.9   */
    4.10  
     5.1 --- a/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.out	Wed Oct 23 15:45:18 2013 -0700
     5.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.out	Wed Oct 23 23:20:32 2013 -0400
     5.3 @@ -24,10 +24,6 @@
     5.4  CantAnnotateStaticClass2.java:58:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB
     5.5  CantAnnotateStaticClass2.java:65:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB
     5.6  CantAnnotateStaticClass2.java:66:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB
     5.7 -CantAnnotateStaticClass2.java:105:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
     5.8 -CantAnnotateStaticClass2.java:107:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
     5.9 -CantAnnotateStaticClass2.java:112:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
    5.10 -CantAnnotateStaticClass2.java:114:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
    5.11  CantAnnotateStaticClass2.java:120:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB
    5.12  CantAnnotateStaticClass2.java:121:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB
    5.13  CantAnnotateStaticClass2.java:128:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB
    5.14 @@ -50,6 +46,10 @@
    5.15  CantAnnotateStaticClass2.java:167:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB
    5.16  CantAnnotateStaticClass2.java:169:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB
    5.17  CantAnnotateStaticClass2.java:171:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB
    5.18 +CantAnnotateStaticClass2.java:105:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
    5.19 +CantAnnotateStaticClass2.java:107:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
    5.20 +CantAnnotateStaticClass2.java:112:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
    5.21 +CantAnnotateStaticClass2.java:114:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
    5.22  CantAnnotateStaticClass2.java:184:35: compiler.err.cant.type.annotate.scoping.1: @Top.TB
    5.23  CantAnnotateStaticClass2.java:186:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB
    5.24  CantAnnotateStaticClass2.java:187:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB
    5.25 @@ -62,4 +62,4 @@
    5.26  CantAnnotateStaticClass2.java:202:44: compiler.err.cant.type.annotate.scoping.1: @Top.TB
    5.27  CantAnnotateStaticClass2.java:203:44: compiler.err.cant.type.annotate.scoping.1: @Top.TB
    5.28  CantAnnotateStaticClass2.java:204:49: compiler.err.cant.type.annotate.scoping: @Top.TA,@Top.TB,@Top.TC
    5.29 -64 errors
    5.30 \ No newline at end of file
    5.31 +64 errors
     6.1 --- a/test/tools/javac/annotations/typeAnnotations/newlocations/MultiCatch.java	Wed Oct 23 15:45:18 2013 -0700
     6.2 +++ b/test/tools/javac/annotations/typeAnnotations/newlocations/MultiCatch.java	Wed Oct 23 23:20:32 2013 -0400
     6.3 @@ -25,7 +25,6 @@
     6.4  
     6.5  /*
     6.6   * @test
     6.7 - * @ignore 8008762 Type annotations failures
     6.8   * @bug 8006775
     6.9   * @summary new type annotation location: multicatch
    6.10   * @author Werner Dietl
     7.1 --- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/MultiCatch.java	Wed Oct 23 15:45:18 2013 -0700
     7.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/MultiCatch.java	Wed Oct 23 23:20:32 2013 -0400
     7.3 @@ -25,7 +25,6 @@
     7.4  
     7.5  /*
     7.6   * @test
     7.7 - * @ignore 8008762 Type annotation failures
     7.8   * @bug 8006732 8006775
     7.9   * @summary Test population of reference info for multicatch exception parameters
    7.10   * @author Werner Dietl

mercurial