java/non-final-call-in-constructor: a call made inside a lambda in the constructor 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ó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
The report points at the unqualifiedCallToNonAbstractMethod predicate, which requires the call's enclosing callable to be the constructor (result.getEnclosingCallable() = c), so a call inside a lambda is missed. Start from the query java/non-final-call-in-constructor and the two seed files, CtorSeed.java and CtorVariant.java, and run the query on each database to confirm the gap. Done means the lambda case is reported at line 6 of CtorVariant.java while the existing results on CtorSeed.java stay the same.
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 toString() in the constructor of CtorSeed.Senior: Junior overrides it, the override reads name, and name is only assigned after super() returns, so new Junior() throws. Move the call into a lambda that the constructor runs right away (CtorVariant) and nothing is reported, though the call still happens during construction with the same effect.
Probably unqualifiedCallToNonAbstractMethod, which requires the call's enclosing callable to be the constructor (result.getEnclosingCallable() = c). Inside the lambda the enclosing callable is the lambda's own method.
Query: java/non-final-call-in-constructor (codeql/java-queries 1.1.10)
CodeQL CLI: 2.27.2
Code samples
seed/CtorSeed.java:
public class CtorSeed {
public static class Senior {
public Senior() {
toString(); // overridden in Junior, reads a field not yet set
}
public String toString() {
return "Senior";
}
}
public static class Junior extends Senior {
private String name;
public Junior() {
super();
name = "Junior";
}
public String toString() {
return name.toUpperCase(); // NullPointerException when called from Senior()
}
}
}
variant/CtorVariant.java:
public class CtorVariant {
public static class Senior {
public Senior() {
Runnable r = () -> {
toString(); // the same call, inside a lambda run at once; not reported
};
r.run();
}
public String toString() {
return "Senior";
}
}
public static class Junior extends Senior {
private String name;
public Junior() {
super();
name = "Junior";
}
public String toString() {
return name.toUpperCase();
}
}
}
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
"Non-final method invocation in constructor" on the toString() call inside the lambda in CtorVariant.java (line 6), as on CtorSeed.java (line 5).
Output of the commands above:
### CodeQL 2.27.2 query: java/non-final-call-in-constructor
### 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/)
"Non-final method invocation in constructor","If a constructor calls a method that is overridden in a subclass
--- VARIANT -- expected: query fires, actual: not reported (the bug) (variant/)
(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ự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
code-yeongyu/senpi#5713 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Bump calamine to 0.38: RUSTSEC-2026-0436 (CFB/OLE2 panic and unbounded allocation) fails cargo auditĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
docling-project/docling.rs#979 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: careagents
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
aks129/HealthClawGuardrails#1110 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
auth bug security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày