8006732: support correct bytecode storage of type annotations in multicatch
Fix issue with annotations being added before attribution, which causes multicatch not to work right and several tests to fail. Reviewed-by: jfranck, jjg
This commit is contained in:
parent
017ea08922
commit
fb5a684124
@ -4096,8 +4096,9 @@ public class Attr extends JCTree.Visitor {
|
||||
}
|
||||
|
||||
private static List<Attribute.TypeCompound> fromAnnotations(List<JCAnnotation> annotations) {
|
||||
if (annotations.isEmpty())
|
||||
if (annotations.isEmpty()) {
|
||||
return List.nil();
|
||||
}
|
||||
|
||||
ListBuffer<Attribute.TypeCompound> buf = new ListBuffer<>();
|
||||
for (JCAnnotation anno : annotations) {
|
||||
@ -4109,6 +4110,10 @@ public class Attr extends JCTree.Visitor {
|
||||
// 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();
|
||||
}
|
||||
|
@ -573,6 +573,8 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
|
||||
|
||||
Env<AttrContext> localEnv = methodEnv(tree, env);
|
||||
|
||||
annotate.enterStart();
|
||||
try {
|
||||
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos());
|
||||
try {
|
||||
// Compute the method type
|
||||
@ -605,6 +607,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
|
||||
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.
|
||||
@ -612,6 +615,9 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
|
||||
|
||||
if (tree.defaultValue != null)
|
||||
annotateDefaultValueLater(tree.defaultValue, localEnv, m);
|
||||
} finally {
|
||||
annotate.enterDone();
|
||||
}
|
||||
}
|
||||
|
||||
/** Create a fresh environment for method bodies.
|
||||
@ -639,6 +645,8 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
|
||||
localEnv.info.staticLevel++;
|
||||
}
|
||||
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos());
|
||||
annotate.enterStart();
|
||||
try {
|
||||
try {
|
||||
if (TreeInfo.isEnumInit(tree)) {
|
||||
attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype);
|
||||
@ -666,10 +674,12 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
|
||||
}
|
||||
|
||||
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.
|
||||
//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();
|
||||
}
|
||||
@ -694,6 +704,9 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
|
||||
annotateLater(tree.mods.annotations, localEnv, v, tree.pos());
|
||||
typeAnnotate(tree.vartype, env, v, tree.pos());
|
||||
v.pos = tree.pos;
|
||||
} finally {
|
||||
annotate.enterDone();
|
||||
}
|
||||
}
|
||||
// where
|
||||
void checkType(JCTree tree, Type type, String diag) {
|
||||
|
@ -1652,9 +1652,10 @@ public class Gen extends JCTree.Visitor {
|
||||
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 @@ public class Gen extends JCTree.Visitor {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
*/
|
||||
|
||||
|
@ -24,10 +24,6 @@ CantAnnotateStaticClass2.java:57:12: compiler.err.cant.type.annotate.scoping.1:
|
||||
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:165:22: compiler.err.cant.type.annotate.scoping.1:
|
||||
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
|
||||
|
@ -25,7 +25,6 @@ import java.lang.annotation.*;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @ignore 8008762 Type annotations failures
|
||||
* @bug 8006775
|
||||
* @summary new type annotation location: multicatch
|
||||
* @author Werner Dietl
|
||||
|
@ -25,7 +25,6 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @ignore 8008762 Type annotation failures
|
||||
* @bug 8006732 8006775
|
||||
* @summary Test population of reference info for multicatch exception parameters
|
||||
* @author Werner Dietl
|
||||
|
Loading…
x
Reference in New Issue
Block a user