Skip to content

Java: Restrict results to source literals. #20054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ReservedUnicodeInLiteral extends Literal {

ReservedUnicodeInLiteral() {
not this instanceof CharacterLiteral and
this.getCompilationUnit().fromSource() and
exists(int codePoint |
this.getLiteral().codePointAt(indexStart) = codePoint and
(
Expand All @@ -45,6 +46,9 @@ where
literal.getIndexStart() = charIndex and
literal.getLiteral().codePointAt(charIndex) = codePoint and
not literal.getEnclosingCallable() instanceof LikelyTestMethod and
// Kotlin extraction doesn't preserve the literal value so we can't distinguish
// between control characters and their escaped versions, so we exclude Kotlin
// to avoid false positives.
not literal.getFile().isKotlinSourceFile()
select literal,
"Literal value contains control or non-printable whitespace character(s) starting with Unicode code point "
Expand Down