mirror of
https://github.com/github/codeql.git
synced 2026-04-25 16:55:19 +02:00
Java: Added new query java/visible-for-testing-abuse
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
| packageone/SourcePackage.java:8:21:8:32 | Annotated.m1 | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:9:29:9:30 | m1 | element |
|
||||
| packagetwo/Source.java:7:17:7:29 | f(...) | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:12:16:12:16 | f | element |
|
||||
| packagetwo/Source.java:8:20:8:30 | Annotated.m | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:7:19:7:19 | m | element |
|
||||
| packagetwo/Source.java:9:28:9:47 | new AnnotatedClass(...) | Access of $@ annotated with VisibleForTesting found in production code. | packageone/AnnotatedClass.java:4:14:4:27 | AnnotatedClass | element |
|
||||
@@ -0,0 +1 @@
|
||||
Violations of Best Practice/Implementation Hiding/VisibleForTestingAbuse.ql
|
||||
@@ -0,0 +1,6 @@
|
||||
package packageone;
|
||||
|
||||
@VisibleForTesting
|
||||
public class AnnotatedClass {
|
||||
public AnnotatedClass() {}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package packageone;
|
||||
|
||||
import packagetwo.Annotated;
|
||||
|
||||
public class SourcePackage extends Annotated {
|
||||
void f() {
|
||||
AnnotatedClass a = new AnnotatedClass(); // COMPLIANT - same package
|
||||
String s1 = Annotated.m1; // NON_COMPLIANT
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package packageone;
|
||||
|
||||
public @interface VisibleForTesting {
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package packagetwo;
|
||||
|
||||
import packageone.*;
|
||||
|
||||
public class Annotated {
|
||||
@VisibleForTesting
|
||||
static String m;
|
||||
@VisibleForTesting
|
||||
static protected String m1;
|
||||
|
||||
@VisibleForTesting
|
||||
static int f() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package packagetwo;
|
||||
|
||||
import packageone.*;
|
||||
|
||||
public class Source {
|
||||
void f() {
|
||||
int i = Annotated.f(); // NON_COMPLIANT
|
||||
String s = Annotated.m; // NON_COMPLIANT
|
||||
AnnotatedClass a = new AnnotatedClass(); // NON_COMPLIANT
|
||||
String s1 = Annotated.m1; // COMPLIANT - same package
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package packagetwo;
|
||||
|
||||
import packageone.*;
|
||||
|
||||
public class Test {
|
||||
void f() {
|
||||
int i = Annotated.f(); // COMPLIANT
|
||||
String s = Annotated.m; // COMPLIANT
|
||||
AnnotatedClass a = new AnnotatedClass(); // COMPLIANT
|
||||
String s1 = Annotated.m1; // COMPLIANT
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user