Skip to content

Commit f0ef909

Browse files
committed
AnnotationPosition: avoid IOOBE on annotated var keyword usages
Fixes google#1327. See google#2867.
1 parent c2afa4e commit f0ef909

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

core/src/main/java/com/google/errorprone/bugpatterns/AnnotationPosition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private static List<ErrorProneToken> annotationTokens(
167167
endPos = state.getEndPosition(methodTree);
168168
}
169169
} else if (tree instanceof JCVariableDecl) {
170-
endPos = ((JCVariableDecl) tree).getType().getStartPosition();
170+
endPos = state.getEndPosition(((JCVariableDecl) tree).getModifiers());
171171
} else if (tree instanceof JCClassDecl) {
172172
JCClassDecl classTree = (JCClassDecl) tree;
173173
endPos =

core/src/test/java/com/google/errorprone/bugpatterns/AnnotationPositionTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,4 +513,20 @@ public void parameters_withInterspersedModifiers() {
513513
"}")
514514
.doTest(TEXT_MATCH);
515515
}
516+
517+
@Test
518+
public void varKeyword() {
519+
refactoringHelper
520+
.addInputLines(
521+
"Test.java",
522+
"import com.google.errorprone.annotations.Var;",
523+
"class T {",
524+
" void m() {",
525+
" @Var var x = 1;",
526+
" x = 2;",
527+
" }",
528+
"}")
529+
.expectUnchanged()
530+
.doTest(TEXT_MATCH);
531+
}
516532
}

0 commit comments

Comments
 (0)