diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/AutoValueBoxedValues.java b/core/src/main/java/com/google/errorprone/bugpatterns/AutoValueBoxedValues.java index 7a8c240d0f4..06025ebd325 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/AutoValueBoxedValues.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/AutoValueBoxedValues.java @@ -62,7 +62,7 @@ public class AutoValueBoxedValues extends BugChecker implements ClassTreeMatcher @Override public Description matchClass(ClassTree tree, VisitorState state) { - if (!hasAnnotation(tree, AutoValue.class.getName(), state)) { + if (!hasAnnotation(tree, AutoValue.class.getName(), state) || isSuppressed(tree, state)) { return NO_MATCH; } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/AutoValueBoxedValuesTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/AutoValueBoxedValuesTest.java index 93a0b1fa96b..a7c6cc92aa9 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/AutoValueBoxedValuesTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/AutoValueBoxedValuesTest.java @@ -345,6 +345,34 @@ public void mixedTypes_refactoring() { .doTest(); } + @Test + public void unnecessaryBoxedTypes_suppressWarningsForClass() { + compilationHelper + .addSourceLines( + "in/Test.java", + mergeLines( + lines( + "import com.google.auto.value.AutoValue;", + "@AutoValue", + "@SuppressWarnings(\"AutoValueBoxedValues\")", + "abstract class Test {", + " public abstract Long longId();", + " public abstract Integer intId();"), + linesWithoutBuilder( + " static Test create(Long longId, Integer intId) {", + " return new AutoValue_Test(longId, intId);", + " }"), + linesWithBuilder( + " @AutoValue.Builder", + " abstract static class Builder {", + " abstract Builder setLongId(Long value);", + " abstract Builder setIntId(Integer value);", + " abstract Test build();", + " }"), + lines("}"))) + .doTest(); + } + @Test public void unnecessaryBoxedTypes_suppressWarnings() { refactoringHelper