United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6919944 incorrect position given for duplicate annotation value error
6919944 : incorrect position given for duplicate annotation value error

Details
Type:
Bug
Submit Date:
2010-01-25
Status:
Closed
Updated Date:
2012-01-13
Project Name:
JDK
Resolved Date:
2012-01-13
Component:
tools
OS:
generic
Sub-Component:
javac
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:
7

Related Reports
Relates:
Relates:

Sub Tasks

Description
The upcoming fix for errors in the positions for tree nodes has uncovered a latent error in the position used to report a duplicate annotation value.

For example, look at test/tools/javac/typeAnnotations/failures/common/arrayclass/DuplicateAnnotationValue.java

The standard (non-raw) output is
test/tools/javac/typeAnnotations/failures/common/arrayclass/DuplicateAnnotationValue.java:10: duplicate annotation member value value in A
    Object a = String @A(value = 2, value = 1) [].class;
                                            ^
1 error


(caret under the "1")


With the fixes to 6654037/6919889, the output changes to 

test/tools/javac/typeAnnotations/failures/common/arrayclass/DuplicateAnnotationValue.java:10: duplicate annotation member value value in A
    Object a = String @A(value = 2, value = 1) [].class;
                                          ^
1 error

However, this is still not correct -- the correct place for the caret is at the beginning of the second instance of "value".

                                    

Comments
SUGGESTED FIX

diff -r 0eaf89e08564 src/share/classes/com/sun/tools/javac/comp/Check.java
--- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Wed Jan 20 16:12:26 2010 -0800
+++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Mon Jan 25 13:30:38 2010 -0800
@@ -2047,7 +2047,7 @@
             Symbol m = TreeInfo.symbol(assign.lhs);
             if (m == null || m.type.isErroneous()) continue;
             if (!members.remove(m))
-                log.error(arg.pos(), "duplicate.annotation.member.value",
+                log.error(assign.lhs.pos(), "duplicate.annotation.member.value",
                           m.name, a.type);
             if (assign.rhs.getTag() == ANNOTATION)
                 validateAnnotation((JCAnnotation)assign.rhs);
                                     
2010-01-25
EVALUATION

The tree for the position in the error is the tree for the assignment ("value = 2").  A better position would be for the left hand side of the assignment ("value").
                                     
2010-01-25



Hardware and Software, Engineered to Work Together