# HG changeset patch # User emc # Date 1382584832 14400 # Node ID d2fa3f7e964ebba80facf5f7b9eec25a31718a9b # Parent 31fe30e2deac890589976dcd1ea05ba0117459a4 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 diff -r 31fe30e2deac -r d2fa3f7e964e src/share/classes/com/sun/tools/javac/comp/Attr.java --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Oct 23 15:45:18 2013 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Oct 23 23:20:32 2013 -0400 @@ -4096,8 +4096,9 @@ } private static List fromAnnotations(List annotations) { - if (annotations.isEmpty()) + if (annotations.isEmpty()) { return List.nil(); + } ListBuffer buf = new ListBuffer<>(); for (JCAnnotation anno : annotations) { @@ -4109,6 +4110,10 @@ // Any better solutions? buf.append((Attribute.TypeCompound) anno.attribute); } + // Eventually we will want to throw an exception here, but + // we can't do that just yet, because it gets triggered + // when attempting to attach an annotation that isn't + // defined. } return buf.toList(); } diff -r 31fe30e2deac -r d2fa3f7e964e src/share/classes/com/sun/tools/javac/comp/MemberEnter.java --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Wed Oct 23 15:45:18 2013 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Wed Oct 23 23:20:32 2013 -0400 @@ -573,45 +573,51 @@ Env localEnv = methodEnv(tree, env); - DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); + annotate.enterStart(); try { - // Compute the method type - m.type = signature(m, tree.typarams, tree.params, - tree.restype, tree.recvparam, - tree.thrown, - localEnv); - } finally { - deferredLintHandler.setPos(prevLintPos); - } + DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); + try { + // Compute the method type + m.type = signature(m, tree.typarams, tree.params, + tree.restype, tree.recvparam, + tree.thrown, + localEnv); + } finally { + deferredLintHandler.setPos(prevLintPos); + } - if (types.isSignaturePolymorphic(m)) { - m.flags_field |= SIGNATURE_POLYMORPHIC; - } + if (types.isSignaturePolymorphic(m)) { + m.flags_field |= SIGNATURE_POLYMORPHIC; + } - // Set m.params - ListBuffer params = new ListBuffer(); - JCVariableDecl lastParam = null; - for (List l = tree.params; l.nonEmpty(); l = l.tail) { - JCVariableDecl param = lastParam = l.head; - params.append(Assert.checkNonNull(param.sym)); - } - m.params = params.toList(); + // Set m.params + ListBuffer params = new ListBuffer(); + JCVariableDecl lastParam = null; + for (List l = tree.params; l.nonEmpty(); l = l.tail) { + JCVariableDecl param = lastParam = l.head; + params.append(Assert.checkNonNull(param.sym)); + } + m.params = params.toList(); + + // mark the method varargs, if necessary + if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0) + m.flags_field |= Flags.VARARGS; - // mark the method varargs, if necessary - if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0) - m.flags_field |= Flags.VARARGS; + localEnv.info.scope.leave(); + if (chk.checkUnique(tree.pos(), m, enclScope)) { + enclScope.enter(m); + } - localEnv.info.scope.leave(); - if (chk.checkUnique(tree.pos(), m, enclScope)) { - enclScope.enter(m); + annotateLater(tree.mods.annotations, localEnv, m, tree.pos()); + // Visit the signature of the method. Note that + // TypeAnnotate doesn't descend into the body. + typeAnnotate(tree, localEnv, m, tree.pos()); + + if (tree.defaultValue != null) + annotateDefaultValueLater(tree.defaultValue, localEnv, m); + } finally { + annotate.enterDone(); } - annotateLater(tree.mods.annotations, localEnv, m, tree.pos()); - // Visit the signature of the method. Note that - // TypeAnnotate doesn't descend into the body. - typeAnnotate(tree, localEnv, m, tree.pos()); - - if (tree.defaultValue != null) - annotateDefaultValueLater(tree.defaultValue, localEnv, m); } /** Create a fresh environment for method bodies. @@ -639,61 +645,68 @@ localEnv.info.staticLevel++; } DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); + annotate.enterStart(); try { - if (TreeInfo.isEnumInit(tree)) { - attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype); - } else { - attr.attribType(tree.vartype, localEnv); - if (tree.nameexpr != null) { - attr.attribExpr(tree.nameexpr, localEnv); - MethodSymbol m = localEnv.enclMethod.sym; - if (m.isConstructor()) { - Type outertype = m.owner.owner.type; - if (outertype.hasTag(TypeTag.CLASS)) { - checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type"); - checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name"); + try { + if (TreeInfo.isEnumInit(tree)) { + attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype); + } else { + attr.attribType(tree.vartype, localEnv); + if (tree.nameexpr != null) { + attr.attribExpr(tree.nameexpr, localEnv); + MethodSymbol m = localEnv.enclMethod.sym; + if (m.isConstructor()) { + Type outertype = m.owner.owner.type; + if (outertype.hasTag(TypeTag.CLASS)) { + checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type"); + checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name"); + } else { + log.error(tree, "receiver.parameter.not.applicable.constructor.toplevel.class"); + } } else { - log.error(tree, "receiver.parameter.not.applicable.constructor.toplevel.class"); + checkType(tree.vartype, m.owner.type, "incorrect.receiver.type"); + checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name"); } - } else { - checkType(tree.vartype, m.owner.type, "incorrect.receiver.type"); - checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name"); } } + } finally { + deferredLintHandler.setPos(prevLintPos); + } + + if ((tree.mods.flags & VARARGS) != 0) { + //if we are entering a varargs parameter, we need to + //replace its type (a plain array type) with the more + //precise VarargsType --- we need to do it this way + //because varargs is represented in the tree as a + //modifier on the parameter declaration, and not as a + //distinct type of array node. + ArrayType atype = (ArrayType)tree.vartype.type.unannotatedType(); + tree.vartype.type = atype.makeVarargs(); + } + Scope enclScope = enter.enterScope(env); + VarSymbol v = + new VarSymbol(0, tree.name, tree.vartype.type, enclScope.owner); + v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree); + tree.sym = v; + if (tree.init != null) { + v.flags_field |= HASINIT; + if ((v.flags_field & FINAL) != 0 && + needsLazyConstValue(tree.init)) { + Env initEnv = getInitEnv(tree, env); + initEnv.info.enclVar = v; + v.setLazyConstValue(initEnv(tree, initEnv), attr, tree); + } } + if (chk.checkUnique(tree.pos(), v, enclScope)) { + chk.checkTransparentVar(tree.pos(), v, enclScope); + enclScope.enter(v); + } + annotateLater(tree.mods.annotations, localEnv, v, tree.pos()); + typeAnnotate(tree.vartype, env, v, tree.pos()); + v.pos = tree.pos; } finally { - deferredLintHandler.setPos(prevLintPos); - } - - if ((tree.mods.flags & VARARGS) != 0) { - //if we are entering a varargs parameter, we need to replace its type - //(a plain array type) with the more precise VarargsType --- we need - //to do it this way because varargs is represented in the tree as a modifier - //on the parameter declaration, and not as a distinct type of array node. - ArrayType atype = (ArrayType)tree.vartype.type.unannotatedType(); - tree.vartype.type = atype.makeVarargs(); + annotate.enterDone(); } - Scope enclScope = enter.enterScope(env); - VarSymbol v = - new VarSymbol(0, tree.name, tree.vartype.type, enclScope.owner); - v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree); - tree.sym = v; - if (tree.init != null) { - v.flags_field |= HASINIT; - if ((v.flags_field & FINAL) != 0 && - needsLazyConstValue(tree.init)) { - Env initEnv = getInitEnv(tree, env); - initEnv.info.enclVar = v; - v.setLazyConstValue(initEnv(tree, initEnv), attr, tree); - } - } - if (chk.checkUnique(tree.pos(), v, enclScope)) { - chk.checkTransparentVar(tree.pos(), v, enclScope); - enclScope.enter(v); - } - annotateLater(tree.mods.annotations, localEnv, v, tree.pos()); - typeAnnotate(tree.vartype, env, v, tree.pos()); - v.pos = tree.pos; } // where void checkType(JCTree tree, Type type, String diag) { diff -r 31fe30e2deac -r d2fa3f7e964e src/share/classes/com/sun/tools/javac/jvm/Gen.java --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Wed Oct 23 15:45:18 2013 -0700 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Wed Oct 23 23:20:32 2013 -0400 @@ -1652,9 +1652,10 @@ startpc, end, code.curCP(), catchType); if (subCatch.type.isAnnotated()) { - // All compounds share the same position, simply update the - // first one. - subCatch.type.getAnnotationMirrors().head.position.type_index = catchType; + for (Attribute.TypeCompound tc : + subCatch.type.getAnnotationMirrors()) { + tc.position.type_index = catchType; + } } } gaps = gaps.tail; @@ -1668,9 +1669,10 @@ startpc, endpc, code.curCP(), catchType); if (subCatch.type.isAnnotated()) { - // All compounds share the same position, simply update the - // first one. - subCatch.type.getAnnotationMirrors().head.position.type_index = catchType; + for (Attribute.TypeCompound tc : + subCatch.type.getAnnotationMirrors()) { + tc.position.type_index = catchType; + } } } } diff -r 31fe30e2deac -r d2fa3f7e964e test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.java --- a/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.java Wed Oct 23 15:45:18 2013 -0700 +++ b/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.java Wed Oct 23 23:20:32 2013 -0400 @@ -3,7 +3,6 @@ * @bug 8006733 8006775 * @summary Ensure behavior for nested types is correct. * @author Werner Dietl - * @ignore * @compile/fail/ref=CantAnnotateStaticClass2.out -XDrawDiagnostics CantAnnotateStaticClass2.java */ diff -r 31fe30e2deac -r d2fa3f7e964e test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.out --- a/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.out Wed Oct 23 15:45:18 2013 -0700 +++ b/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.out Wed Oct 23 23:20:32 2013 -0400 @@ -24,10 +24,6 @@ CantAnnotateStaticClass2.java:58:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:65:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:66:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:105:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:107:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:112:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:114:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:120:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:121:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:128:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB @@ -50,6 +46,10 @@ CantAnnotateStaticClass2.java:167:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:169:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:171:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:105:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:107:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:112:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:114:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:184:35: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:186:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:187:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB @@ -62,4 +62,4 @@ CantAnnotateStaticClass2.java:202:44: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:203:44: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:204:49: compiler.err.cant.type.annotate.scoping: @Top.TA,@Top.TB,@Top.TC -64 errors \ No newline at end of file +64 errors diff -r 31fe30e2deac -r d2fa3f7e964e test/tools/javac/annotations/typeAnnotations/newlocations/MultiCatch.java --- a/test/tools/javac/annotations/typeAnnotations/newlocations/MultiCatch.java Wed Oct 23 15:45:18 2013 -0700 +++ b/test/tools/javac/annotations/typeAnnotations/newlocations/MultiCatch.java Wed Oct 23 23:20:32 2013 -0400 @@ -25,7 +25,6 @@ /* * @test - * @ignore 8008762 Type annotations failures * @bug 8006775 * @summary new type annotation location: multicatch * @author Werner Dietl diff -r 31fe30e2deac -r d2fa3f7e964e test/tools/javac/annotations/typeAnnotations/referenceinfos/MultiCatch.java --- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/MultiCatch.java Wed Oct 23 15:45:18 2013 -0700 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/MultiCatch.java Wed Oct 23 23:20:32 2013 -0400 @@ -25,7 +25,6 @@ /* * @test - * @ignore 8008762 Type annotation failures * @bug 8006732 8006775 * @summary Test population of reference info for multicatch exception parameters * @author Werner Dietl