mirror of
https://github.com/github/codeql.git
synced 2026-04-27 17:55:19 +02:00
Java: Expanded test suite of java/visible-for-testing-abuse
This commit is contained in:
@@ -4,7 +4,31 @@ import packagetwo.Annotated;
|
||||
|
||||
public class SourcePackage extends Annotated {
|
||||
void f() {
|
||||
AnnotatedClass a = new AnnotatedClass(); // COMPLIANT - same package
|
||||
// Fields - cross-package access (only accessible ones)
|
||||
// String s = Annotated.m; // Cannot access package-private from different package
|
||||
String s1 = Annotated.m1; // $ Alert
|
||||
String s2 = Annotated.m2; // $ Alert
|
||||
// String s3 = Annotated.m3; // Cannot access private field
|
||||
|
||||
// Methods - cross-package access (only accessible ones)
|
||||
// int i = Annotated.f(); // Cannot access package-private from different package
|
||||
// int i1 = Annotated.fPrivate(); // Cannot access private method
|
||||
int i2 = Annotated.fPublic(); // $ Alert
|
||||
int i3 = Annotated.fProtected(); // $ Alert
|
||||
|
||||
// Same package class
|
||||
AnnotatedClass a = new AnnotatedClass(); // COMPLIANT - same package
|
||||
|
||||
// Lambda usage - cross-package (only accessible members)
|
||||
Runnable lambda = () -> {
|
||||
// String lambdaS = Annotated.m; // Cannot access package-private
|
||||
String lambdaS1 = Annotated.m1; // $ Alert
|
||||
String lambdaS2 = Annotated.m2; // $ Alert
|
||||
|
||||
// int lambdaI = Annotated.f(); // Cannot access package-private
|
||||
int lambdaI2 = Annotated.fPublic(); // $ Alert
|
||||
int lambdaI3 = Annotated.fProtected(); // $ Alert
|
||||
};
|
||||
lambda.run();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user