Skip to content

Commit 52d2dd7

Browse files
committed
Java: Make equivalent fix to the telemetry queries as made for C#.
1 parent 6c6b4ce commit 52d2dd7

File tree

5 files changed

+43
-52
lines changed

5 files changed

+43
-52
lines changed

java/ql/src/Telemetry/ExternalApi.qll

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,29 +105,40 @@ deprecated class ExternalAPI = ExternalApi;
105105
int resultLimit() { result = 1000 }
106106

107107
/**
108-
* Holds if the relevant usage count of `api` is `usages`.
108+
* Holds if it is relevant to count usages of `api`.
109109
*/
110-
signature predicate relevantUsagesSig(ExternalApi api, int usages);
110+
signature predicate relevantApi(ExternalApi api);
111111

112112
/**
113113
* Given a predicate to count relevant API usages, this module provides a predicate
114114
* for restricting the number or returned results based on a certain limit.
115115
*/
116-
module Results<relevantUsagesSig/2 getRelevantUsages> {
117-
private int getOrder(ExternalApi api) {
118-
api =
119-
rank[result](ExternalApi a, int usages |
120-
getRelevantUsages(a, usages)
116+
module Results<relevantApi/1 getRelevantUsages> {
117+
private int getUsages(string apiName) {
118+
result =
119+
strictcount(Call c, ExternalApi api |
120+
c.getCallee().getSourceDeclaration() = api and
121+
not c.getFile() instanceof GeneratedFile and
122+
apiName = api.getApiName() and
123+
getRelevantUsages(api)
124+
)
125+
}
126+
127+
private int getOrder(string apiInfo) {
128+
apiInfo =
129+
rank[result](string info, int usages |
130+
usages = getUsages(info)
121131
|
122-
a order by usages desc, a.getApiName()
132+
info order by usages desc, info
123133
)
124134
}
125135

126136
/**
127-
* Holds if `api` is being used `usages` times and if it is
128-
* in the top results (guarded by resultLimit).
137+
* Holds if there exists an API with `apiName` that is being used `usages` times
138+
* and if it is in the top results (guarded by resultLimit).
129139
*/
130-
predicate restrict(ExternalApi api, int usages) {
131-
getRelevantUsages(api, usages) and getOrder(api) <= resultLimit()
140+
predicate restrict(string apiName, int usages) {
141+
usages = getUsages(apiName) and
142+
getOrder(apiName) <= resultLimit()
132143
}
133144
}

java/ql/src/Telemetry/SupportedExternalSinks.ql

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,11 @@
99
import java
1010
import ExternalApi
1111

12-
private predicate getRelevantUsages(ExternalApi api, int usages) {
12+
private predicate relevant(ExternalApi api) {
1313
not api.isUninteresting() and
14-
api.isSink() and
15-
usages =
16-
strictcount(Call c |
17-
c.getCallee().getSourceDeclaration() = api and
18-
not c.getFile() instanceof GeneratedFile
19-
)
14+
api.isSink()
2015
}
2116

22-
from ExternalApi api, int usages
23-
where Results<getRelevantUsages/2>::restrict(api, usages)
24-
select api.getApiName() as apiname, usages order by usages desc
17+
from string apiName, int usages
18+
where Results<relevant/1>::restrict(apiName, usages)
19+
select apiName, usages order by usages desc

java/ql/src/Telemetry/SupportedExternalSources.ql

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,11 @@
99
import java
1010
import ExternalApi
1111

12-
private predicate getRelevantUsages(ExternalApi api, int usages) {
12+
private predicate relevant(ExternalApi api) {
1313
not api.isUninteresting() and
14-
api.isSource() and
15-
usages =
16-
strictcount(Call c |
17-
c.getCallee().getSourceDeclaration() = api and
18-
not c.getFile() instanceof GeneratedFile
19-
)
14+
api.isSource()
2015
}
2116

22-
from ExternalApi api, int usages
23-
where Results<getRelevantUsages/2>::restrict(api, usages)
24-
select api.getApiName() as apiname, usages order by usages desc
17+
from string apiName, int usages
18+
where Results<relevant/1>::restrict(apiName, usages)
19+
select apiName, usages order by usages desc

java/ql/src/Telemetry/SupportedExternalTaint.ql

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,11 @@
99
import java
1010
import ExternalApi
1111

12-
private predicate getRelevantUsages(ExternalApi api, int usages) {
12+
private predicate relevant(ExternalApi api) {
1313
not api.isUninteresting() and
14-
api.hasSummary() and
15-
usages =
16-
strictcount(Call c |
17-
c.getCallee().getSourceDeclaration() = api and
18-
not c.getFile() instanceof GeneratedFile
19-
)
14+
api.hasSummary()
2015
}
2116

22-
from ExternalApi api, int usages
23-
where Results<getRelevantUsages/2>::restrict(api, usages)
24-
select api.getApiName() as apiname, usages order by usages desc
17+
from string apiName, int usages
18+
where Results<relevant/1>::restrict(apiName, usages)
19+
select apiName, usages order by usages desc

java/ql/src/Telemetry/UnsupportedExternalAPIs.ql

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,12 @@ import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
1111
import semmle.code.java.dataflow.internal.NegativeSummary
1212
import ExternalApi
1313

14-
private predicate getRelevantUsages(ExternalApi api, int usages) {
14+
private predicate relevant(ExternalApi api) {
1515
not api.isUninteresting() and
1616
not api.isSupported() and
17-
not api instanceof FlowSummaryImpl::Public::NegativeSummarizedCallable and
18-
usages =
19-
strictcount(Call c |
20-
c.getCallee().getSourceDeclaration() = api and
21-
not c.getFile() instanceof GeneratedFile
22-
)
17+
not api instanceof FlowSummaryImpl::Public::NegativeSummarizedCallable
2318
}
2419

25-
from ExternalApi api, int usages
26-
where Results<getRelevantUsages/2>::restrict(api, usages)
27-
select api.getApiName() as apiname, usages order by usages desc
20+
from string apiName, int usages
21+
where Results<relevant/1>::restrict(apiName, usages)
22+
select apiName, usages order by usages desc

0 commit comments

Comments
 (0)