diff --git a/check_api/src/main/java/com/google/errorprone/VisitorState.java b/check_api/src/main/java/com/google/errorprone/VisitorState.java index 1cfa680abee..075215aae4c 100644 --- a/check_api/src/main/java/com/google/errorprone/VisitorState.java +++ b/check_api/src/main/java/com/google/errorprone/VisitorState.java @@ -264,6 +264,9 @@ public ErrorProneOptions errorProneOptions() { } public void reportMatch(Description description) { + if (description == null || description == Description.NO_MATCH) { + return; + } // TODO(cushon): creating Descriptions with the default severity and updating them here isn't // ideal (we could forget to do the update), so consider removing severity from Description. // Instead, there could be another method on the listener that took a description and a diff --git a/check_api/src/main/java/com/google/errorprone/scanner/Scanner.java b/check_api/src/main/java/com/google/errorprone/scanner/Scanner.java index 2592ec11f5b..a553f0c1640 100644 --- a/check_api/src/main/java/com/google/errorprone/scanner/Scanner.java +++ b/check_api/src/main/java/com/google/errorprone/scanner/Scanner.java @@ -121,9 +121,6 @@ protected Set getCustomSuppressionAnnotations(VisitorState state } protected void reportMatch(Description description, VisitorState state) { - if (description == null || description == Description.NO_MATCH) { - return; - } state.reportMatch(description); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/time/StronglyTypeTimeTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/time/StronglyTypeTimeTest.java index 28deab5c5e5..1102aa642d2 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/time/StronglyTypeTimeTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/time/StronglyTypeTimeTest.java @@ -245,6 +245,19 @@ public void fieldNotPrivate_noMatch() { .doTest(); } + @Test + public void unusedField_noMatch() { + compilationHelper + .addSourceLines( + "Test.java", + "import java.io.Serializable;", + "class Test implements Serializable {", + " private static final long serialVersionUID = 1L;", + "}") + .expectNoDiagnostics() + .doTest(); + } + @Test public void whenJodaAndJavaInstantUsed_fullyQualifiesName() { refactoringHelper