Skip to content

Commit 1fd459e

Browse files
committed
Improve stringification of some erroneous expressions
1 parent 6c8105f commit 1fd459e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

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+
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

0 commit comments

Comments
 (0)