Skip to content

Commit 051d63a

Browse files
authored
Merge pull request github#15740 from smowton/smowton/feature/call-and-type-telemetry
Java: add extraction quality telemetry; improve stringification of some erroneous expressions
2 parents 47bf556 + ef9544c commit 051d63a

File tree

18 files changed

+194
-7
lines changed

18 files changed

+194
-7
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
| Annotation processors enabled: true | 1 |
2+
| Number of calls with call target | 1 |
3+
| Number of calls with missing call target | 4 |
4+
| Number of diagnostics from CodeQL Java extractor with severity 5 | 10 |
5+
| Number of diagnostics from CodeQL Java extractor with severity 6 | 2 |
6+
| Number of expressions with known type | 1 |
7+
| Number of expressions with unknown type | 6 |
8+
| Number of files | 607 |
9+
| Number of files with extension class | 604 |
10+
| Number of files with extension java | 1 |
11+
| Number of files with extension properties | 1 |
12+
| Number of lines of code | 7 |
13+
| Number of lines of code with extension java | 7 |
14+
| Percentage of calls with call target | 20 |
15+
| Total number of diagnostics from CodeQL Java extractor | 12 |
16+
| Total number of lines | 13 |
17+
| Total number of lines with extension java | 13 |
18+
| Used annotation processor: lombok.launch.AnnotationProcessorHider$AnnotationProcessor | 1 |
19+
| Used annotation processor: lombok.launch.AnnotationProcessorHider$ClaimingProcessor | 1 |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Telemetry/ExtractorInformation.ql
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import abc.Def;
2+
3+
public class Test {
4+
5+
public static void test() {
6+
7+
Def.someMethod();
8+
(new Def()).member().chained();
9+
10+
}
11+
12+
}
13+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"markdownMessage": "Because no usable build tool (Gradle, Maven, etc) was found, build scripts could not be queried for guidance about the appropriate JDK version for the code being extracted, or precise dependency information. The default JDK will be used, and external dependencies will be inferred from the Java package names used.",
3+
"severity": "unknown",
4+
"source": {
5+
"extractorName": "java",
6+
"id": "java/autobuilder/buildless/no-build-tool-advice",
7+
"name": "Java buildless mode found no usable build tool"
8+
},
9+
"visibility": {
10+
"cliSummaryTable": true,
11+
"statusPage": false,
12+
"telemetry": true
13+
}
14+
}
15+
{
16+
"markdownMessage": "Java buildless mode used the system default JDK.",
17+
"severity": "unknown",
18+
"source": {
19+
"extractorName": "java",
20+
"id": "java/autobuilder/buildless/jdk-system-default",
21+
"name": "Java buildless mode used the system default JDK"
22+
},
23+
"visibility": {
24+
"cliSummaryTable": true,
25+
"statusPage": false,
26+
"telemetry": true
27+
}
28+
}
29+
{
30+
"markdownMessage": "Java was extracted in buildless mode. This means that all Java source in the working directory will be scanned, with build tools such as Maven and Gradle only contributing information about external dependencies.",
31+
"severity": "note",
32+
"source": {
33+
"extractorName": "java",
34+
"id": "java/autobuilder/buildless/mode-active",
35+
"name": "Java was extracted in buildless mode"
36+
},
37+
"visibility": {
38+
"cliSummaryTable": true,
39+
"statusPage": true,
40+
"telemetry": true
41+
}
42+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import sys
2+
3+
from create_database_utils import *
4+
from diagnostics_test_utils import *
5+
6+
run_codeql_database_create([], lang="java", extra_env={"CODEQL_EXTRACTOR_JAVA_OPTION_BUILDLESS": "true"})
7+
8+
check_diagnostics()
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
| Number of calls with call target | 1 |
2+
| Number of calls with missing call target | 0 |
3+
| Number of expressions with known type | 0 |
4+
| Number of expressions with unknown type | 0 |
15
| Number of files with extension jar | 1 |
26
| Number of files with extension kt | 1 |
37
| Number of lines of code | 2 |
48
| Number of lines of code with extension kt | 2 |
9+
| Percentage of calls with call target | 100 |
510
| Total number of lines | 3 |
611
| Total number of lines with extension kt | 3 |
712
| Uses Kotlin 2: false | 1 |
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
| Number of calls with call target | 1 |
2+
| Number of calls with missing call target | 0 |
3+
| Number of expressions with known type | 0 |
4+
| Number of expressions with unknown type | 0 |
15
| Number of files with extension jar | 1 |
26
| Number of files with extension kt | 1 |
37
| Number of lines of code | 2 |
48
| Number of lines of code with extension kt | 2 |
9+
| Percentage of calls with call target | 100 |
510
| Total number of lines | 3 |
611
| Total number of lines with extension kt | 3 |
712
| Uses Kotlin 2: true | 1 |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Java expressions with erroneous types (e.g. the result of a call whose callee couldn't be resolved during extraction) are now given a CodeQL `ErrorType` more often.

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,11 @@ class MethodCall extends Expr, Call, @methodaccess {
20652065
override Stmt getEnclosingStmt() { result = Expr.super.getEnclosingStmt() }
20662066

20672067
/** Gets a printable representation of this expression. */
2068-
override string toString() { result = this.printAccess() }
2068+
override string toString() {
2069+
if exists(this.getMethod())
2070+
then result = this.printAccess()
2071+
else result = "<Call to unknown method>"
2072+
}
20692073

20702074
/** Gets a printable representation of this expression. */
20712075
string printAccess() { result = this.getMethod().getName() + "(...)" }
@@ -2128,13 +2132,19 @@ class TypeAccess extends Expr, Annotatable, @typeaccess {
21282132
/** Gets the compilation unit in which this type access occurs. */
21292133
override CompilationUnit getCompilationUnit() { result = Expr.super.getCompilationUnit() }
21302134

2131-
/** Gets a printable representation of this expression. */
2132-
override string toString() {
2135+
private string toNormalString() {
21332136
result = this.getQualifier().toString() + "." + this.getType().toString()
21342137
or
21352138
not this.hasQualifier() and result = this.getType().toString()
21362139
}
21372140

2141+
/** Gets a printable representation of this expression. */
2142+
override string toString() {
2143+
if this.getType() instanceof ErrorType
2144+
then result = "<TypeAccess of ErrorType>"
2145+
else result = this.toNormalString()
2146+
}
2147+
21382148
override string getAPrimaryQlClass() { result = "TypeAccess" }
21392149
}
21402150

java/ql/src/Likely Bugs/Likely Typos/ContradictoryTypeChecks.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ predicate contradictoryTypeCheck(Expr e, Variable v, RefType t, RefType sup, Exp
4040
requiresInstanceOf(e, ssa.getAUse(), t) and
4141
sup = t.getAnAncestor() and
4242
instanceOfCheck(cond, ssa.getAUse(), sup) and
43-
cond.(Guard).controls(e.getBasicBlock(), false)
43+
cond.(Guard).controls(e.getBasicBlock(), false) and
44+
not t instanceof ErrorType and
45+
not sup instanceof ErrorType
4446
)
4547
}
4648

0 commit comments

Comments
 (0)