Skip to content

Commit 3f5b9d0

Browse files
authored
Merge pull request github#6637 from github/alexet/imporve-query
Java: Fix performance issues with future versions of codeql.
2 parents f90d1fd + 81f4822 commit 3f5b9d0

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

java/ql/lib/semmle/code/java/Annotation.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class Annotatable extends Element {
110110
}
111111

112112
/** Gets an annotation that applies to this element. */
113+
cached
113114
Annotation getAnAnnotation() { result.getAnnotatedElement() = this }
114115

115116
/**

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -616,16 +616,21 @@ private predicate elementSpec(
616616
summaryModel(namespace, type, subtypes, name, signature, ext, _, _, _)
617617
}
618618

619+
private predicate relevantCallable(Callable c) { elementSpec(_, _, _, c.getName(), _, _) }
620+
619621
private string paramsStringPart(Callable c, int i) {
620-
i = -1 and result = "("
621-
or
622-
exists(int n, string p | c.getParameterType(n).getErasure().toString() = p |
623-
i = 2 * n and result = p
622+
relevantCallable(c) and
623+
(
624+
i = -1 and result = "("
624625
or
625-
i = 2 * n - 1 and result = "," and n != 0
626+
exists(int n, string p | c.getParameterType(n).getErasure().toString() = p |
627+
i = 2 * n and result = p
628+
or
629+
i = 2 * n - 1 and result = "," and n != 0
630+
)
631+
or
632+
i = 2 * c.getNumberOfParameters() and result = ")"
626633
)
627-
or
628-
i = 2 * c.getNumberOfParameters() and result = ")"
629634
}
630635

631636
private string paramsString(Callable c) {

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ import semmle.code.xml.AndroidManifest
1111
*/
1212
class AndroidComponent extends Class {
1313
AndroidComponent() {
14-
this.getASupertype*().hasQualifiedName("android.app", "Activity") or
15-
this.getASupertype*().hasQualifiedName("android.app", "Service") or
16-
this.getASupertype*().hasQualifiedName("android.content", "BroadcastReceiver") or
17-
this.getASupertype*().hasQualifiedName("android.content", "ContentProvider") or
18-
this.getASupertype*().hasQualifiedName("android.content", "ContentResolver")
14+
// The casts here are due to misoptimisation if they are missing
15+
// but are not needed semantically.
16+
this.(Class).getASupertype*().hasQualifiedName("android.app", "Activity") or
17+
this.(Class).getASupertype*().hasQualifiedName("android.app", "Service") or
18+
this.(Class).getASupertype*().hasQualifiedName("android.content", "BroadcastReceiver") or
19+
this.(Class).getASupertype*().hasQualifiedName("android.content", "ContentProvider") or
20+
this.(Class).getASupertype*().hasQualifiedName("android.content", "ContentResolver")
1921
}
2022

2123
/** The XML element corresponding to this Android component. */

0 commit comments

Comments
 (0)