8054956: Javac reports wrong error offset for unknown identifier of annotation element/value pair
Summary: When reporting an error about unresolvable annotation attribute, use the position of the explicit left-hand-side of the assignment if available, otherwise use the position of the right-hand-side.
Reviewed-by: jfranck
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java Mon Oct 13 11:21:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java Mon Oct 13 17:22:47 2014 +0200
@@ -315,8 +315,10 @@
isError = true;
}
List<JCExpression> args = a.args;
+ boolean elidedValue = false;
if (args.length() == 1 && !args.head.hasTag(ASSIGN)) {
// special case: elided "value=" assumed
+ elidedValue = true;
args.head = make.at(args.head.pos).
Assign(make.Ident(names.value), args.head);
}
@@ -336,7 +338,7 @@
continue;
}
JCIdent left = (JCIdent)assign.lhs;
- Symbol method = rs.resolveQualifiedMethod(assign.rhs.pos(),
+ Symbol method = rs.resolveQualifiedMethod(elidedValue ? assign.rhs.pos() : left.pos(),
env,
a.type,
left.name,
--- a/langtools/test/tools/javac/annotations/neg/Recovery1.out Mon Oct 13 11:21:51 2014 -0400
+++ b/langtools/test/tools/javac/annotations/neg/Recovery1.out Mon Oct 13 17:22:47 2014 +0200
@@ -1,4 +1,4 @@
Recovery1.java:14:5: compiler.err.cant.resolve.location: kindname.class, Marker, , , (compiler.misc.location: kindname.annotation, recovery1.MyAnnotation, null)
Recovery1.java:14:30: compiler.err.cant.resolve.location: kindname.class, Marker, , , (compiler.misc.location: kindname.annotation, recovery1.MyAnnotation, null)
-Recovery1.java:18:43: compiler.err.cant.resolve.location.args: kindname.method, markerToo, , , (compiler.misc.location: kindname.annotation, recovery1.MyAnnotation, null)
+Recovery1.java:18:33: compiler.err.cant.resolve.location.args: kindname.method, markerToo, , , (compiler.misc.location: kindname.annotation, recovery1.MyAnnotation, null)
3 errors
--- a/langtools/test/tools/javac/positions/TreeEndPosTest.java Mon Oct 13 11:21:51 2014 -0400
+++ b/langtools/test/tools/javac/positions/TreeEndPosTest.java Mon Oct 13 17:22:47 2014 +0200
@@ -23,7 +23,7 @@
/*
* @test
- * @bug 8017216 8019422 8019421
+ * @bug 8017216 8019422 8019421 8054956
* @summary verify start and end positions
* @run main TreeEndPosTest
*/
@@ -102,6 +102,7 @@
public static void main(String... args) throws IOException {
testUninitializedVariable();
testMissingAnnotationValue();
+ testUnresolvableAnnotationAttribute();
testFinalVariableWithDefaultConstructor();
testFinalVariableWithConstructor();
}
@@ -115,6 +116,11 @@
null, "@interface Foo { }", "\"vvvv\""));
}
+ static void testUnresolvableAnnotationAttribute() throws IOException {
+ compile(JavaSource.createJavaSource("@Foo(value=\"vvvv\")",
+ null, "@interface Foo { }", "value"));
+ }
+
static void testFinalVariableWithDefaultConstructor() throws IOException {
compile(JavaSource.createJavaSource("private static final String Foo; public void bar() { }",
"private static final String Foo;"));