Skip to content

Commit eb26b4a

Browse files
authored
Merge pull request #6755 from alexet/alexet/cache-params-string
Java: Fix more performance issues with future versions of codeql.
2 parents a3cf721 + 447eb23 commit eb26b4a

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

java/ql/lib/semmle/code/java/dataflow/ExternalFlow.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ private string paramsStringPart(Callable c, int i) {
641641
* Returns the empty string if the callable has no parameters.
642642
* Parameter types are represented by their type erasure.
643643
*/
644+
cached
644645
string paramsString(Callable c) { result = concat(int i | | paramsStringPart(c, i) order by i) }
645646

646647
private Element interpretElement0(

java/ql/lib/semmle/code/java/frameworks/android/Android.qll

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,29 @@ import java
66
import semmle.code.java.dataflow.ExternalFlow
77
import semmle.code.xml.AndroidManifest
88

9+
/**
10+
* Gets a transitive superType avoiding magic optimisation
11+
*/
12+
pragma[nomagic]
13+
private RefType getASuperTypePlus(RefType t) { result = t.getASupertype+() }
14+
15+
/**
16+
* Gets a reflexive/transitive superType avoiding magic optimisation
17+
*/
18+
pragma[inline]
19+
private RefType getASuperTypeStar(RefType t) { result = getASuperTypePlus(t) or result = t }
20+
921
/**
1022
* An Android component. That is, either an activity, a service,
1123
* a broadcast receiver, or a content provider.
1224
*/
1325
class AndroidComponent extends Class {
1426
AndroidComponent() {
15-
// The casts here are due to misoptimisation if they are missing
16-
// but are not needed semantically.
17-
this.(Class).getASupertype*().hasQualifiedName("android.app", "Activity") or
18-
this.(Class).getASupertype*().hasQualifiedName("android.app", "Service") or
19-
this.(Class).getASupertype*().hasQualifiedName("android.content", "BroadcastReceiver") or
20-
this.(Class).getASupertype*().hasQualifiedName("android.content", "ContentProvider") or
21-
this.(Class).getASupertype*().hasQualifiedName("android.content", "ContentResolver")
27+
getASuperTypeStar(this).hasQualifiedName("android.app", "Activity") or
28+
getASuperTypeStar(this).hasQualifiedName("android.app", "Service") or
29+
getASuperTypeStar(this).hasQualifiedName("android.content", "BroadcastReceiver") or
30+
getASuperTypeStar(this).hasQualifiedName("android.content", "ContentProvider") or
31+
getASuperTypeStar(this).hasQualifiedName("android.content", "ContentResolver")
2232
}
2333

2434
/** The XML element corresponding to this Android component. */
@@ -52,25 +62,25 @@ class ExportableAndroidComponent extends AndroidComponent {
5262

5363
/** An Android activity. */
5464
class AndroidActivity extends ExportableAndroidComponent {
55-
AndroidActivity() { this.getASupertype*().hasQualifiedName("android.app", "Activity") }
65+
AndroidActivity() { getASuperTypeStar(this).hasQualifiedName("android.app", "Activity") }
5666
}
5767

5868
/** An Android service. */
5969
class AndroidService extends ExportableAndroidComponent {
60-
AndroidService() { this.getASupertype*().hasQualifiedName("android.app", "Service") }
70+
AndroidService() { getASuperTypeStar(this).hasQualifiedName("android.app", "Service") }
6171
}
6272

6373
/** An Android broadcast receiver. */
6474
class AndroidBroadcastReceiver extends ExportableAndroidComponent {
6575
AndroidBroadcastReceiver() {
66-
this.getASupertype*().hasQualifiedName("android.content", "BroadcastReceiver")
76+
getASuperTypeStar(this).hasQualifiedName("android.content", "BroadcastReceiver")
6777
}
6878
}
6979

7080
/** An Android content provider. */
7181
class AndroidContentProvider extends ExportableAndroidComponent {
7282
AndroidContentProvider() {
73-
this.getASupertype*().hasQualifiedName("android.content", "ContentProvider")
83+
getASuperTypeStar(this).hasQualifiedName("android.content", "ContentProvider")
7484
}
7585

7686
/**
@@ -85,7 +95,7 @@ class AndroidContentProvider extends ExportableAndroidComponent {
8595
/** An Android content resolver. */
8696
class AndroidContentResolver extends AndroidComponent {
8797
AndroidContentResolver() {
88-
this.getASupertype*().hasQualifiedName("android.content", "ContentResolver")
98+
getASuperTypeStar(this).hasQualifiedName("android.content", "ContentResolver")
8999
}
90100
}
91101

java/ql/src/Violations of Best Practice/Naming Conventions/ConfusingOverloading.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ private predicate whitelist(string name) { name = "visit" }
5050
* Method `m` has name `name`, number of parameters `numParams`
5151
* and is declared in `t` or inherited from a supertype of `t`.
5252
*/
53+
pragma[nomagic]
5354
private predicate candidateMethod(RefType t, Method m, string name, int numParam) {
5455
exists(Method n | n.getSourceDeclaration() = m | t.inherits(n)) and
5556
m.getName() = name and

0 commit comments

Comments
 (0)