Skip to content

Commit ef5073b

Browse files
graememorganError Prone Team
authored andcommitted
UnnecessaryQualifier: don't fire on interfaces, in deference to Dagger.
I don't think this is ironclad (abstract classes too, perhaps?) but this is probably good enough to avoid obvious Dagger-related false positives. PiperOrigin-RevId: 782968953
1 parent 3d7b585 commit ef5073b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ public Description matchMethod(MethodTree tree, VisitorState state) {
6464
}
6565

6666
var enclosingClass = state.findEnclosing(ClassTree.class);
67+
if (getSymbol(enclosingClass).isInterface()) {
68+
// This is a sad admission of failure, and also not foolproof. Dagger dependencies can be
69+
// declared in interfaces with no annotations to let us tell, or components can have
70+
// innocent-looking supertypes.
71+
return NO_MATCH;
72+
}
6773
if (CLASS_ANNOTATIONS_EXEMPTING_METHODS.stream()
6874
.anyMatch(anno -> hasAnnotation(enclosingClass, anno, state))) {
6975
return NO_MATCH;

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,18 @@ interface Test {
210210
""")
211211
.doTest();
212212
}
213+
214+
@Test
215+
public void interface_noFinding() {
216+
helper
217+
.addSourceLines(
218+
"Test.java",
219+
"""
220+
interface Test {
221+
@Qual
222+
Object frobnicator();
223+
}
224+
""")
225+
.doTest();
226+
}
213227
}

0 commit comments

Comments
 (0)