Skip to content

Commit 038afc4

Browse files
authored
Merge pull request github#15772 from owen-mc/java/model-generator-exclude-tostring
Java: do not generate models for `toString` and lambda flow methods
2 parents 11142df + 114c17a commit 038afc4

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

java/ql/lib/semmle/code/java/dataflow/internal/ModelExclusions.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,27 @@ private predicate isInternal(CompilationUnit cu) {
5959
cu.getPackage().getName().matches("%internal%")
6060
}
6161

62+
/** A method relating to lambda flow. */
63+
private class LambdaFlowMethod extends Method {
64+
LambdaFlowMethod() {
65+
this.hasQualifiedName("java.lang", "Runnable", "run") or
66+
this.hasQualifiedName("java.util", "Comparator",
67+
["comparing", "comparingDouble", "comparingInt", "comparingLong"]) or
68+
this.hasQualifiedName("java.util.function", "BiConsumer", "accept") or
69+
this.hasQualifiedName("java.util.function", "BiFunction", "apply") or
70+
this.hasQualifiedName("java.util.function", "Consumer", "accept") or
71+
this.hasQualifiedName("java.util.function", "Function", "apply") or
72+
this.hasQualifiedName("java.util.function", "Supplier", "get")
73+
}
74+
}
75+
6276
/** Holds if the given callable is not worth modeling. */
6377
predicate isUninterestingForModels(Callable c) {
6478
isInTestFile(c.getCompilationUnit().getFile()) or
6579
isInternal(c.getCompilationUnit()) or
6680
c instanceof MainMethod or
81+
c instanceof ToStringMethod or
82+
c instanceof LambdaFlowMethod or
6783
c instanceof StaticInitializer or
6884
exists(FunctionalExpr funcExpr | c = funcExpr.asMethod()) or
6985
c.getDeclaringType() instanceof TestLibrary or
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
| java.awt | 0 | 0 | 2 | 1 | 3 | 0.6666666666666666 | 0.0 | 0.6666666666666666 | 0.0 | NaN | 0.3333333333333333 |
2-
| java.io | 0 | 0 | 22 | 15 | 37 | 0.5945945945945946 | 0.0 | 0.5945945945945946 | 0.0 | NaN | 0.40540540540540543 |
3-
| java.lang | 0 | 0 | 62 | 94 | 156 | 0.3974358974358974 | 0.0 | 0.3974358974358974 | 0.0 | NaN | 0.6025641025641025 |
2+
| java.io | 0 | 0 | 21 | 15 | 36 | 0.5833333333333334 | 0.0 | 0.5833333333333334 | 0.0 | NaN | 0.4166666666666667 |
3+
| java.lang | 0 | 0 | 57 | 88 | 145 | 0.3931034482758621 | 0.0 | 0.3931034482758621 | 0.0 | NaN | 0.6068965517241379 |
44
| java.lang.invoke | 0 | 0 | 0 | 1 | 1 | 0.0 | 0.0 | 0.0 | NaN | NaN | 1.0 |
55
| java.lang.reflect | 0 | 0 | 0 | 4 | 4 | 0.0 | 0.0 | 0.0 | NaN | NaN | 1.0 |
6-
| java.math | 0 | 0 | 0 | 16 | 16 | 0.0 | 0.0 | 0.0 | NaN | NaN | 1.0 |
7-
| java.net | 0 | 0 | 5 | 0 | 5 | 1.0 | 0.0 | 1.0 | 0.0 | NaN | 0.0 |
6+
| java.math | 0 | 0 | 0 | 15 | 15 | 0.0 | 0.0 | 0.0 | NaN | NaN | 1.0 |
7+
| java.net | 0 | 0 | 4 | 0 | 4 | 1.0 | 0.0 | 1.0 | 0.0 | NaN | 0.0 |
88
| java.nio | 0 | 0 | 2 | 3 | 5 | 0.4 | 0.0 | 0.4 | 0.0 | NaN | 0.6 |
99
| java.nio.charset | 0 | 0 | 0 | 1 | 1 | 0.0 | 0.0 | 0.0 | NaN | NaN | 1.0 |
10-
| java.nio.file | 0 | 0 | 7 | 1 | 8 | 0.875 | 0.0 | 0.875 | 0.0 | NaN | 0.125 |
10+
| java.nio.file | 0 | 0 | 6 | 1 | 7 | 0.8571428571428571 | 0.0 | 0.8571428571428571 | 0.0 | NaN | 0.14285714285714285 |
1111
| java.sql | 0 | 0 | 1 | 15 | 16 | 0.0625 | 0.0 | 0.0625 | 0.0 | NaN | 0.9375 |
1212
| java.text | 0 | 0 | 0 | 5 | 5 | 0.0 | 0.0 | 0.0 | NaN | NaN | 1.0 |
1313
| java.time | 0 | 0 | 0 | 17 | 17 | 0.0 | 0.0 | 0.0 | NaN | NaN | 1.0 |
1414
| java.time.chrono | 0 | 0 | 0 | 1 | 1 | 0.0 | 0.0 | 0.0 | NaN | NaN | 1.0 |
1515
| java.time.format | 0 | 0 | 0 | 2 | 2 | 0.0 | 0.0 | 0.0 | NaN | NaN | 1.0 |
16-
| java.util | 0 | 0 | 86 | 66 | 152 | 0.5657894736842105 | 0.0 | 0.5657894736842105 | 0.0 | NaN | 0.4342105263157895 |
16+
| java.util | 0 | 0 | 86 | 64 | 150 | 0.5733333333333334 | 0.0 | 0.5733333333333334 | 0.0 | NaN | 0.4266666666666667 |
1717
| java.util.concurrent | 0 | 0 | 9 | 9 | 18 | 0.5 | 0.0 | 0.5 | 0.0 | NaN | 0.5 |
1818
| java.util.concurrent.atomic | 0 | 0 | 2 | 11 | 13 | 0.15384615384615385 | 0.0 | 0.15384615384615385 | 0.0 | NaN | 0.8461538461538461 |
1919
| java.util.concurrent.locks | 0 | 0 | 0 | 2 | 2 | 0.0 | 0.0 | 0.0 | NaN | NaN | 1.0 |
20-
| java.util.function | 0 | 0 | 0 | 6 | 6 | 0.0 | 0.0 | 0.0 | NaN | NaN | 1.0 |
20+
| java.util.function | 0 | 0 | 0 | 1 | 1 | 0.0 | 0.0 | 0.0 | NaN | NaN | 1.0 |
2121
| java.util.logging | 0 | 0 | 1 | 1 | 2 | 0.5 | 0.0 | 0.5 | 0.0 | NaN | 0.5 |
2222
| java.util.regex | 0 | 0 | 3 | 1 | 4 | 0.75 | 0.0 | 0.75 | 0.0 | NaN | 0.25 |
2323
| java.util.stream | 0 | 0 | 18 | 8 | 26 | 0.6923076923076923 | 0.0 | 0.6923076923076923 | 0.0 | NaN | 0.3076923076923077 |

java/ql/test/utils/modelgenerator/dataflow/CaptureSummaryModels.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
| p;Joiner;false;merge;(Joiner);;Argument[this];ReturnValue;value;df-generated |
2222
| p;Joiner;false;setEmptyValue;(CharSequence);;Argument[0];Argument[this];taint;df-generated |
2323
| p;Joiner;false;setEmptyValue;(CharSequence);;Argument[this];ReturnValue;value;df-generated |
24-
| p;Joiner;false;toString;();;Argument[this];ReturnValue;taint;df-generated |
2524
| p;MultipleImpl2$IInterface;true;m;(Object);;Argument[0];ReturnValue;taint;df-generated |
2625
| p;MultipleImpls$Strat2;true;getValue;();;Argument[this];ReturnValue;taint;df-generated |
2726
| p;MultipleImpls$Strategy;true;doSomething;(String);;Argument[0];Argument[this];taint;df-generated |

0 commit comments

Comments
 (0)