Skip to content

Commit 21c0422

Browse files
authored
Merge pull request #15499 from github/max-schaefer/automodel-functional-interface-expr
Automodel: Do not consider `@FunctionalInterface`-typed expressions as candidates.
2 parents 6b13a8c + e47b021 commit 21c0422

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

java/ql/automodel/src/AutomodelApplicationModeCharacteristics.qll

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,15 @@ private class OtherArgumentToModeledMethodCharacteristic extends Characteristics
600600
}
601601
}
602602

603+
/**
604+
* Holds if the type of the given expression is annotated with `@FunctionalInterface`.
605+
*/
606+
predicate hasFunctionalInterfaceType(Expr e) {
607+
exists(RefType tp | tp = e.getType().getErasure() |
608+
tp.getAnAssociatedAnnotation().getType().hasQualifiedName("java.lang", "FunctionalInterface")
609+
)
610+
}
611+
603612
/**
604613
* A characteristic that marks functional expression as likely not sinks.
605614
*
@@ -608,7 +617,11 @@ private class OtherArgumentToModeledMethodCharacteristic extends Characteristics
608617
private class FunctionValueCharacteristic extends CharacteristicsImpl::LikelyNotASinkCharacteristic {
609618
FunctionValueCharacteristic() { this = "function value" }
610619

611-
override predicate appliesToEndpoint(Endpoint e) { e.asNode().asExpr() instanceof FunctionalExpr }
620+
override predicate appliesToEndpoint(Endpoint e) {
621+
exists(Expr expr | expr = e.asNode().asExpr() |
622+
expr instanceof FunctionalExpr or hasFunctionalInterfaceType(expr)
623+
)
624+
}
612625
}
613626

614627
/**

java/ql/automodel/test/AutomodelApplicationModeExtraction/Test.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.concurrent.atomic.AtomicReference;
1010
import java.util.function.Supplier;
1111
import java.io.File;
12+
import java.io.FileFilter;
1213
import java.nio.file.FileVisitOption;
1314
import java.net.URLConnection;
1415
import java.util.concurrent.FutureTask;
@@ -22,7 +23,7 @@ public static void main(String[] args) throws Exception {
2223
}
2324

2425
public static void callSupplier(Supplier<String> supplier) {
25-
supplier.get(); // $ sourceModelCandidate=get():ReturnValue sinkModelCandidate=get():Argument[this]
26+
supplier.get(); // $ sourceModelCandidate=get():ReturnValue
2627
}
2728

2829
public static void copyFiles(Path source, Path target, CopyOption option) throws Exception {
@@ -65,6 +66,12 @@ public static void FilesWalkExample(Path p, FileVisitOption o) throws Exception
6566
public static void WebSocketExample(URLConnection c) throws Exception {
6667
c.getInputStream(); // $ sinkModelCandidate=getInputStream():Argument[this] positiveSourceExample=getInputStream():ReturnValue(remote) // not a source candidate (manual modeling)
6768
}
69+
70+
public static void fileFilterExample(File f, FileFilter ff) {
71+
f.listFiles( // $ sinkModelCandidate=listFiles(FileFilter):Argument[this]
72+
ff
73+
); // $ sourceModelCandidate=listFiles(FileFilter):ReturnValue
74+
}
6875
}
6976

7077
class OverrideTest extends Exception {

0 commit comments

Comments
 (0)