Skip to content

Commit 4149968

Browse files
committed
Java: Remove the hardcoded path filter that excluded CodeQL's own unit tests from the java/visible-for-testing-abuse query.
1 parent 4705ad2 commit 4149968

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,6 @@ where
9393
// not when the accessing method or any enclosing method is @VisibleForTesting (test-to-test communication)
9494
not isWithinVisibleForTestingContext(e.getEnclosingCallable()) and
9595
// not when used in annotation contexts
96-
not e.getParent*() instanceof Annotation and
97-
// also omit our own ql unit test where it is acceptable
98-
not e.getEnclosingCallable()
99-
.getFile()
100-
.getAbsolutePath()
101-
.matches("%java/ql/test/query-tests/%Test.java")
96+
not e.getParent*() instanceof Annotation
10297
select e, "Access of $@ annotated with VisibleForTesting found in production code.", annotated,
10398
"element"

java/ql/test/query-tests/VisibleForTestingAbuse/VisibleForTestingAbuse.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515
| packagetwo/Source.java:20:28:20:47 | new AnnotatedClass(...) | Access of $@ annotated with VisibleForTesting found in production code. | packageone/AnnotatedClass.java:4:14:4:27 | AnnotatedClass | element |
1616
| packagetwo/Source.java:24:30:24:40 | Annotated.m | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:7:19:7:19 | m | element |
1717
| packagetwo/Source.java:28:27:28:39 | f(...) | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:16:16:16:16 | f | element |
18+
| packagetwo/Test.java:24:30:24:40 | Annotated.m | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:7:19:7:19 | m | element |
19+
| packagetwo/Test.java:28:27:28:39 | f(...) | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:16:16:16:16 | f | element |

java/ql/test/query-tests/VisibleForTestingAbuse/packagetwo/Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ void f() {
2121

2222
// Lambda usage
2323
Runnable lambda = () -> {
24-
String lambdaS = Annotated.m; // COMPLIANT
24+
String lambdaS = Annotated.m; // $ SPURIOUS: Alert
2525
String lambdaS1 = Annotated.m1; // COMPLIANT
2626
String lambdaS2 = Annotated.m2; // COMPLIANT
2727

28-
int lambdaI = Annotated.f(); // COMPLIANT
28+
int lambdaI = Annotated.f(); // $ SPURIOUS: Alert
2929
int lambdaI2 = Annotated.fPublic(); // COMPLIANT
3030
int lambdaI3 = Annotated.fProtected(); // COMPLIANT
3131
};

0 commit comments

Comments
 (0)