java/local-shadows-field: a local declared inside a lambda or anonymous class body is not reported
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- Nửa ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
The likely cause is the shadows predicate in Shadowing.qll, which requires the local's callable to be declared by the class that owns the field (method.getDeclaringType() = c). Start by running the three samples (ShadowSeed, ShadowVariant, ShadowControl) against java/local-shadows-field and confirming only the seed fires. Done when the local inside the lambda and inside the anonymous class is reported, and the seed case still is.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description of the issue
The query reports the local String[] arr in ShadowSeed.getArr(), which has the same name as the field the method reads as this.arr. Declare the same local inside a lambda in that method (ShadowVariant) or inside an anonymous class (ShadowControl) and nothing is reported, though it still shadows the field and the method still reads this.arr.
Probably the shadows predicate in Shadowing.qll: it requires the local's callable to be declared by the class that declares the field (method.getDeclaringType() = c). Inside a lambda the callable is the lambda's own method, and inside an anonymous class it's that class's method.
Query: java/local-shadows-field (codeql/java-queries 1.1.10)
CodeQL CLI: 2.27.2
Code samples
seed/ShadowSeed.java:
public class ShadowSeed {
String[] arr;
String[] getArr() {
String[] arr; // shadows the field; the query fires here
return this.arr;
}
}
variant/ShadowVariant.java:
public class ShadowVariant {
String[] arr;
String[] getArr() {
Runnable r = () -> {
String[] arr; // the same local inside a lambda body; not reported
};
r.run();
return this.arr;
}
}
control/ShadowControl.java:
public class ShadowControl {
String[] arr;
String[] getArr() {
Runnable r = new Runnable() {
public void run() {
String[] arr; // inside an anonymous class; not reported either
}
};
r.run();
return this.arr;
}
}
How to reproduce
codeql database create db --language=java --build-mode=none \
--source-root=<one directory> --overwrite
codeql database analyze db \
codeql/java-queries:codeql-suites/java-security-and-quality.qls \
--format=csv --output=out.csv
# one database per directory
Expected result
"Potentially confusing name: method ... also refers to field arr (as this.arr)" on the local in ShadowVariant.java (line 5) and in ShadowControl.java (line 6), as on ShadowSeed.java (line 4).
Output of the commands above:
### CodeQL 2.27.2 query: java/local-shadows-field
### suite: java-security-and-quality.qls, --build-mode=none, per-file isolated databases
### extraction JDK: openjdk version "21.0.11" 2026-04-21 LTS
--- SEED -- expected: query fires (seed/)
"Possible confusion of local and field","A method in which a variable is declared with the same name as a fiel
--- VARIANT -- expected: query fires, actual: not reported (the bug) (variant/)
(query reported nothing)
--- CONTROL -- the same construct in an anonymous class, expected: query fires (control/)
(query reported nothing)
- Ngôn ngữ chính
- CodeQL
- Star
- 10.3k
- Fork
- 2.1k
- Merge trung bình
- 1 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 126
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của github/codeql
-
JavaScript externs model StorageEvent() with no type argumentCó thể đã có người làm @asgerf đã nhận 14 ngày trước. Đang mởfalse-positive javascript
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
github/codeql#22632 · 3 bình luận · 1 reaction · 2 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add AlertSuppression.ql for Rust (inline // codeql[...] suppression)Có thể đã có người làm @cnuss đã nhận 215 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
github/codeql#21637 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
false-positive
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
github/codeql#21076 · 3 bình luận · 3 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
General issueĐang mởquestion
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 5/100
Maintainer thường phản hồi trong vòng 1 ngày
-
False positive java/local-variable-is-never-read for Kotlin data object-generated equals temporariesĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của github/codeql
Issue tương tự
-
Temp-directory guard in schedule_diagnostics() never matches on macOS (/var vs /private/var)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
REditorSupport/languageserver#833 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
nolabs-ai/nono-packs#65 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
NousResearch/hermes-agent#148376 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
rescript-lang/rescript#9182 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100