java/unused-reference-type and java/unused-container: silenced by any annotation, even an empty one
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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)
- 主要言語
- CodeQL
- スター
- 10.3k
- フォーク
- 2.1k
- 平均マージ
- 1日 22時間
- マージ済み PR(30日)
- 126
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
github/codeql のほかの issue
-
JavaScript externs model StorageEvent() with no type argument対応中かも @asgerf が 14 日前に担当しました。 オープンfalse-positive javascript
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
github/codeql#22632 · コメント 3 件 · リアクション 1 件 · 担当者 2 名 ·
メンテナーはふだん 1 日以内に返信
-
Add AlertSuppression.ql for Rust (inline // codeql[...] suppression)対応中かも @cnuss が 215 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
github/codeql#21637 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
false-positive
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
github/codeql#21076 · コメント 3 件 · リアクション 3 件 ·
メンテナーはふだん 1 日以内に返信
-
General issueオープンquestion
難易度 5/5 1週間以上 初心者へのやさしさ 5/100
メンテナーはふだん 1 日以内に返信
-
False positive java/local-variable-is-never-read for Kotlin data object-generated equals temporariesオープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
[bug] A prompt queued during a run is assessed without its text対応中かも @jwiegley が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
DevMortimer/pi-warden#211 ·
メンテナーはふだん 1 日以内に返信
-
check-relative-paths reports links to existing directories as missing対応中かも @reidbaker-agent が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
google/skills_lint.dart#202 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
HorusGoul/trizum#559 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
get_all_subclasses must deduplicate by class identity対応中かも @Gambit-Checkmate が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 15 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
versatiles-org/versatiles-rs#306 ·