Skip to content

Commit cd0af0f

Browse files
committed
Ignore types with methods which have annotations
The motivation is test classes in JUnit 4 and 5 are currently FPs for this. They have methods with `@Test`, so this should fix the FPs.
1 parent 050dcb1 commit cd0af0f

File tree

2 files changed

+1
-1
lines changed

2 files changed

+1
-1
lines changed

java/ql/src/Violations of Best Practice/Dead Code/DeadRefTypes.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ predicate dead(RefType dead) {
4949
not dead instanceof AnonymousClass and
5050
// Exclude classes that look like they may be reflectively constructed.
5151
not dead.getAnAnnotation() instanceof ReflectiveAccessAnnotation and
52+
not dead.getAMethod().getAnAnnotation() instanceof ReflectiveAccessAnnotation and
5253
// Insist all source ancestors are dead as well.
5354
forall(RefType t | t.fromSource() and t = getASuperTypePlus(dead) | dead(t)) and
5455
// Exclude compiler generated classes (e.g. declaring type of adapter functions in Kotlin)
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
| ClassWithAnnotatedMethod.java:1:7:1:30 | ClassWithAnnotatedMethod | Unused class: ClassWithAnnotatedMethod is not referenced within this codebase. If not used as an external API it should be removed. |
21
| UnusedClass.java:1:7:1:17 | UnusedClass | Unused class: UnusedClass is not referenced within this codebase. If not used as an external API it should be removed. |

0 commit comments

Comments
 (0)