Skip to content

Commit 910bdfb

Browse files
klueverError Prone Team
authored andcommitted
Add a regression test that demonstrates false positive unused imports warning when enum constants are used as annotation values on record components.
PiperOrigin-RevId: 962195245
1 parent 7608619 commit 910bdfb

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,46 @@ public record Test(int z, @One int x, int y) {}
511511
.doTest();
512512
}
513513

514+
@Test
515+
public void recordComponentAnnotation_enumConstant() {
516+
testHelper
517+
.addInputLines(
518+
"p/Test.java",
519+
"""
520+
package p;
521+
522+
import static java.lang.annotation.ElementType.FIELD;
523+
524+
import java.lang.annotation.ElementType;
525+
import java.lang.annotation.Target;
526+
527+
public record Test(@Tag(FIELD) int x) {
528+
@Target(ElementType.RECORD_COMPONENT)
529+
@interface Tag {
530+
ElementType value();
531+
}
532+
}
533+
""")
534+
.addOutputLines(
535+
"out/p/Test.java",
536+
"""
537+
package p;
538+
539+
import java.lang.annotation.ElementType;
540+
import java.lang.annotation.Target;
541+
542+
public record Test(@Tag(FIELD) int x) {
543+
@Target(ElementType.RECORD_COMPONENT)
544+
@interface Tag {
545+
ElementType value();
546+
}
547+
}
548+
""")
549+
// TODO(b/544015068): this should be expectUnchanged() and allowBreakingChanges() removed
550+
.allowBreakingChanges()
551+
.doTest();
552+
}
553+
514554
@Test
515555
public void shadowed_apparentUsageReported() {
516556
compilationTestHelper

0 commit comments

Comments
 (0)