Repository navigation
Expand file tree
/
Copy pathStream.qll
More file actions
76 lines (62 loc) · 2.25 KB
/
Copy pathStream.qll
File metadata and controls
76 lines (62 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/** Definitions related to `java.util.stream`. */
overlay[local?]
module;
private import semmle.code.java.dataflow.FlowSummary
private class CollectCall extends MethodCall {
CollectCall() {
this.getMethod()
.getSourceDeclaration()
.hasQualifiedName("java.util.stream", "Stream", "collect")
}
}
private class Collector extends MethodCall {
Collector() {
this.getMethod().getDeclaringType().hasQualifiedName("java.util.stream", "Collectors")
}
predicate hasName(string name) { this.getMethod().hasName(name) }
}
private class CollectToContainer extends SyntheticCallable {
CollectToContainer() { this = "java.util.stream.collect()+Collectors.[toList,...]" }
override Call getACall() {
result
.(CollectCall)
.getArgument(0)
.(Collector)
.hasName([
"maxBy", "minBy", "toCollection", "toList", "toSet", "toUnmodifiableList",
"toUnmodifiableSet"
])
}
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
input = "Argument[this].Element" and
output = "ReturnValue.Element" and
preservesValue = true
}
}
private class CollectToJoining extends SyntheticCallable {
CollectToJoining() { this = "java.util.stream.collect()+Collectors.joining" }
override Call getACall() { result.(CollectCall).getArgument(0).(Collector).hasName("joining") }
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
input = "Argument[this].Element" and
output = "ReturnValue" and
preservesValue = false
}
override Type getReturnType() { result instanceof TypeString }
}
private class CollectToGroupingBy extends SyntheticCallable {
CollectToGroupingBy() {
this = "java.util.stream.collect()+Collectors.[groupingBy(Function),...]"
}
override Call getACall() {
exists(Method m |
m = result.(CollectCall).getArgument(0).(Collector).getMethod() and
m.hasName(["groupingBy", "groupingByConcurrent", "partitioningBy"]) and
m.getNumberOfParameters() = 1
)
}
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
input = "Argument[this].Element" and
output = "ReturnValue.MapValue.Element" and
preservesValue = true
}
}