Skip to content

Commit cc497be

Browse files
committed
Java: Fix VisibleForTestingAbuse false positives in annotations
1 parent a0b3aa6 commit cc497be

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

java/ql/src/Violations of Best Practice/Implementation Hiding/VisibleForTestingAbuse.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ where
9595
not e.getEnclosingCallable() instanceof LikelyTestMethod and
9696
// not when the accessing method or any enclosing method is @VisibleForTesting (test-to-test communication)
9797
not isWithinVisibleForTestingContext(e.getEnclosingCallable()) and
98+
// not when used in annotation contexts
99+
not e.getParent*() instanceof Annotation and
98100
// also omit our own ql unit test where it is acceptable
99101
not e.getEnclosingCallable()
100102
.getFile()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package packagetwo;
2+
3+
import packageone.*;
4+
5+
@interface Range {
6+
int min() default 0;
7+
int max() default 100;
8+
}
9+
10+
public class UseWithinAnnotation {
11+
@VisibleForTesting
12+
static final int MAX_LISTING_LENGTH_MIN = 1;
13+
@VisibleForTesting
14+
static final int MAX_LISTING_LENGTH_MAX = 1000;
15+
16+
@Range(min = MAX_LISTING_LENGTH_MIN, max = MAX_LISTING_LENGTH_MAX)
17+
private int maxListingLength = MAX_LISTING_LENGTH_MAX;
18+
}

0 commit comments

Comments
 (0)