java/unused-reference-type and java/unused-container: silenced by any annotation, even an empty one
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
- 35/100
Hướng nghiên cứu
Start with the java/unused-reference-type query and the ReflectiveAccessAnnotation check it uses, which treats any annotation other than Override, Deprecated, SuppressWarnings and SafeVarargs as reflective access. Reproduce with the seed/ and variant/ samples in the issue, one database per directory. Done means an empty, program-declared annotation no longer silences the unused-class and container alerts, or the help pages document the exemption.
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
seed/WRAnnotatedType.java declares an unused private nested class and seed/WRAnnotatedContainer.java a private list that's only written to, and the queries report both. Each file also declares an empty annotation type @interface Tag {}, with no retention and no meaning to any framework. Putting @Tag on the class and on the list (variant/) silences both alerts, though nothing else changed.
The queries treat every annotation except Override, Deprecated, SuppressWarnings and SafeVarargs as a sign of reflective access (ReflectiveAccessAnnotation), even one the program declares itself and nothing reads. The help pages don't mention any annotation exemption.
Query: java/unused-reference-type (codeql/java-queries 1.1.10)
CodeQL CLI: 2.27.2
Code samples
seed/WRAnnotatedContainer.java:
import java.util.ArrayList;
import java.util.List;
class WRAnnotatedContainer {
@interface Tag {
}
private List<String> names = new ArrayList<>();
void m() {
names.add("x");
}
}
seed/WRAnnotatedType.java:
class WRAnnotatedType {
@interface Tag {
}
private class Unused {
}
void m() {
}
}
variant/WRAnnotatedContainer.java:
import java.util.ArrayList;
import java.util.List;
class WRAnnotatedContainer {
@interface Tag {
}
@Tag
private List<String> names = new ArrayList<>();
void m() {
names.add("x");
}
}
variant/WRAnnotatedType.java:
class WRAnnotatedType {
@interface Tag {
}
@Tag
private class Unused {
}
void m() {
}
}
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
"Unused class" on the annotated Unused in variant/WRAnnotatedType.java and "The contents of this container are never accessed" on names in variant/WRAnnotatedContainer.java, as on the seed/ files. Or, if any annotation is meant to be an exemption, the help pages should say so.
Output of the commands above:
### CodeQL 2.27.2 query: java/unused-reference-type
### 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/)
"Unused classes and interfaces","A non-public class or interface that is not used anywhere in the program wast
"Unused classes and interfaces","A non-public class or interface that is not used anywhere in the program wast
"Unused classes and interfaces","A non-public class or interface that is not used anywhere in the program wast
"Container contents are never accessed","A collection or map whose contents are never queried or accessed is u
--- 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
- 2 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 137
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
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 47/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 47/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ự
-
Issue: ready for confirmation Reported on 2.4.9 Triage: Dev.Experience
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
magento/magento2#41773 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 5 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
NousResearch/hermes-agent#148799 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
normalizePath removes the Windows device namespace prefixCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug mcp small
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
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
ai-driven-dev/framework#1147 ·
Maintainer thường phản hồi trong vòng 1 ngày