github / github/codeql

Java: VariableAssign matches local variable declaration without initializer

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

Description

The [documentation for `VariableAssign`](https://codeql.github.com/codeql-standard-libraries/java/semmle/code/java/Expr.qll/type.Expr$VariableAssign.html) says:
> An assignment to a variable or an initialization of the variable.

However, it seems to be matching local variable declarations without implicit or explicit initializer as well.
```ql
import java

from VariableAssign varAssign
where
varAssign.getParent() instanceof LocalVariableDeclStmt
and not exists(varAssign.(LocalVariableDeclExpr).getInit())
select varAssign
```
[Query Console link](https://lgtm.com/query/7298207966820430029/)

This matches for example the following:
```java
int result; // VariableAssign
```

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.