Skip to content

Commit 3ebb7cf

Browse files
Merge pull request github#11269 from joefarebrother/stub-gen-invalid-ids
Java: Stub generator: Exclude invalid identifiers from generated stubs
2 parents 0c14759 + 8d9b106 commit 3ebb7cf

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

java/ql/src/utils/stub-generator/Stubs.qll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77

88
import java
99

10+
/** Holds if `id` is a valid Java identifier. */
11+
bindingset[id]
12+
private predicate isValidIdentifier(string id) { id.regexpMatch("[\\w_$]+") }
13+
1014
/** A type that should be in the generated code. */
1115
abstract private class GeneratedType extends ClassOrInterface {
1216
GeneratedType() {
1317
not this instanceof AnonymousClass and
1418
not this.isLocal() and
15-
not this.getPackage() instanceof ExcludedPackage
19+
not this.getPackage() instanceof ExcludedPackage and
20+
isValidIdentifier(this.getName())
1621
}
1722

1823
private string stubKeyword() {
@@ -108,7 +113,8 @@ abstract private class GeneratedType extends ClassOrInterface {
108113
not result.isPrivate() and
109114
not result.isPackageProtected() and
110115
not result instanceof StaticInitializer and
111-
not result instanceof InstanceInitializer
116+
not result instanceof InstanceInitializer and
117+
isValidIdentifier(result.getName())
112118
}
113119

114120
final Type getAGeneratedType() {

0 commit comments

Comments
 (0)