github / github/codeql

Java: `StringLiteral` matches String concatenation of two String literals

Open
#5,469 5 comments 0 reactions 0 assignees View on GitHub
documentation Java question
Dominant language
CodeQL
Stars
10.1k
Forks
2.1k
Avg merge
2d 15h
Merged PRs (30d)
141

Description

It appears the class `StringLiteral` matches String concatenation of two String literals.
This is not how the JLS [defines a String literal](https://docs.oracle.com/javase/specs/jls/se16/html/jls-3.html#jls-3.10.5). Instead they should be matched as separate String literals being operands of an `AddExpr` (which is a `CompileTimeConstantExpr`).

Query finding these erroneous `StringLiteral`s:
```ql
import java

from StringLiteral s
where
exists(s.getLiteral().indexOf("+"))
and not exists(s.getValue().indexOf("+"))
select s
```
[Query Console link](https://lgtm.com/query/1720584166166636188/)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.