github / github/codeql

Java: `TryStmt` resource variable declaration is `LocalVariableDeclStmt` instead of `LocalVariableDeclExpr`

Đang mở
#5,783 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Java question
Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
141

Mô tả

### Description
The CodeQL class `TryStmt` models variable declarations in try-with-resources as `LocalVariableDeclStmt`.
This appears to be inconsistent with how the JLS defines them:
- [JLS 16 §14.20.3](https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-14.20.3):
```
Resource:
LocalVariableDeclaration
VariableAccess
```
- [JLS 16 §14.4](https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-LocalVariableDeclaration)
> A local variable declaration can appear in the following locations:
>- a local variable declaration statement in a block (§14.4.2)
>- the header of a basic for statement (§14.14.1)
>- the header of an enhanced for statement (§14.14.2)
>- the resource specification of a try-with-resources statement (§14.20.3)
>- a pattern (§14.30.1)

CodeQL models "local variable declaration statement in a block" (§14.4.2) as `LocalVariableDeclStmt`, other cases such as `for` statement variables are modeled as `LocalVariableDeclExpr`.
The only exception is the resource of a try-with-resources statement which is currently modeled as `LocalVariableDeclStmt`; this seems incorrect and should probably be a `LocalVariableDeclExpr` instead.

### Example
(See also `TryStmt::getAResourceDecl` result type)
```ql
import java

from LocalVariableDeclStmt varDeclStmt
where any(TryStmt s).getAResourceDecl() = varDeclStmt
select varDeclStmt
```
[Query Console link](https://lgtm.com/query/2939006923879317681/)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.