Skip to content

Commit 6af0bca

Browse files
committed
Java: Avoid generating contradicting summary and neutral summary models.
1 parent 03d4025 commit 6af0bca

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

java/ql/src/utils/modelgenerator/internal/CaptureModelsSpecific.qll

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Type = J::Type;
2222

2323
class Unit = J::Unit;
2424

25+
class Callable = J::Callable;
26+
2527
private J::Method superImpl(J::Method m) {
2628
result = m.getAnOverride() and
2729
not exists(result.getAnOverride()) and
@@ -36,7 +38,7 @@ private predicate isInfrequentlyUsed(J::CompilationUnit cu) {
3638
/**
3739
* Holds if it is relevant to generate models for `api`.
3840
*/
39-
private predicate isRelevantForModels(J::Callable api) {
41+
private predicate isRelevantForModels(Callable api) {
4042
not isUninterestingForModels(api) and
4143
not isInfrequentlyUsed(api.getCompilationUnit()) and
4244
// Disregard all APIs that have a manual model.
@@ -48,7 +50,7 @@ private predicate isRelevantForModels(J::Callable api) {
4850
/**
4951
* Holds if it is relevant to generate models for `api` based on data flow analysis.
5052
*/
51-
predicate isRelevantForDataFlowModels(J::Callable api) {
53+
predicate isRelevantForDataFlowModels(Callable api) {
5254
isRelevantForModels(api) and
5355
(not api.getDeclaringType() instanceof J::Interface or exists(api.getBody()))
5456
}
@@ -61,7 +63,7 @@ predicate isRelevantForTypeBasedFlowModels = isRelevantForModels/1;
6163
* In the Standard library and 3rd party libraries it the Callables that can be called
6264
* from outside the library itself.
6365
*/
64-
class TargetApiSpecific extends J::Callable {
66+
class TargetApiSpecific extends Callable {
6567
TargetApiSpecific() {
6668
this.isPublic() and
6769
this.fromSource() and
@@ -71,6 +73,15 @@ class TargetApiSpecific extends J::Callable {
7173
) and
7274
isRelevantForModels(this)
7375
}
76+
77+
/**
78+
* Gets the callable that a model will be lifted to, if any.
79+
*/
80+
Callable lift() {
81+
exists(Method m | m = superImpl(this) and m.fromSource() | result = m)
82+
or
83+
not exists(superImpl(this)) and result = this
84+
}
7485
}
7586

7687
private string isExtensible(J::RefType ref) {
@@ -84,9 +95,7 @@ private string typeAsModel(J::RefType type) {
8495
}
8596

8697
private J::RefType bestTypeForModel(TargetApiSpecific api) {
87-
if exists(superImpl(api))
88-
then superImpl(api).fromSource() and result = superImpl(api).getDeclaringType()
89-
else result = api.getDeclaringType()
98+
result = api.lift().getDeclaringType()
9099
}
91100

92101
/**
@@ -200,7 +209,7 @@ string returnNodeAsOutput(DataFlowImplCommon::ReturnNodeExt node) {
200209
/**
201210
* Gets the enclosing callable of `ret`.
202211
*/
203-
J::Callable returnNodeEnclosingCallable(DataFlowImplCommon::ReturnNodeExt ret) {
212+
Callable returnNodeEnclosingCallable(DataFlowImplCommon::ReturnNodeExt ret) {
204213
result = DataFlowImplCommon::getNodeEnclosingCallable(ret).asCallable()
205214
}
206215

java/ql/src/utils/modelgenerator/internal/CaptureSummaryFlowQuery.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ string captureFlow(DataFlowTargetApi api) {
7777
* A neutral model is generated, if there does not exist any summary model.
7878
*/
7979
string captureNoFlow(DataFlowTargetApi api) {
80-
not exists(captureFlow(api)) and
80+
not exists(DataFlowTargetApi api0 | exists(captureFlow(api0)) and api0.lift() = api.lift()) and
8181
result = ModelPrinting::asNeutralSummaryModel(api)
8282
}

0 commit comments

Comments
 (0)