InlineTrivialConstant misses an empty-string constant with a parenthesized initializer
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 72/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- java
- 領域
- testing-qa
調査の方向性
InlineTrivialConstant matcherから始め、初期化式のマッチングがParenthesizedTreeを処理するか確認してください。issueでは手掛かりとしてASTHelpers.stripParenthesesが挙げられています。報告された例と見逃された空文字列の例を、このチェックの既存のテストと比較してください。両方の初期化式で検出結果が出て、このチェックのテストが通れば完了です。
索引モデルが issue の本文から書いたものです。
説明
Error Prone version
Error Prone 2.49.0 (javac 21.0.8, --source/--target 21)
Affected checks
InlineTrivialConstant
Description
Adding redundant parentheses around an empty-string initializer causes InlineTrivialConstant to miss a trivial constant. The check reports private static final String EMPTY = "";, but does not report private static final String EMPTY = ("");.
Per JLS §15.8.5, parentheses around an expression do not change its value, type, or constant-expression status. The parenthesized empty string is still the same trivial constant.
I verified the following pair on Error Prone 2.49.0:
| Check | Rewrite | BEFORE | AFTER | Effect |
|---|---|---|---|---|
InlineTrivialConstant |
"" → ("") |
1 | 0 | false negative |
The matcher appears to inspect the initializer without looking through ParenthesizedTree. A possible fix is to unwrap the initializer before matching it, for example with ASTHelpers.stripParentheses.
Reproducers
InlineTrivialConstant — ("") is missed
// BEFORE — 1 finding
public class Sample {
private static final String EMPTY = "";
}
// AFTER — 0 findings
public class Sample {
private static final String EMPTY = ("");
}
Expected behavior
Both versions should produce 1 InlineTrivialConstant finding. Adding redundant parentheses around the empty-string initializer does not change its value or constant-expression status.
Actual behavior
The BEFORE version produces 1 finding. The AFTER version produces 0 findings after the empty-string initializer is parenthesized.
- 主要言語
- Java
- スター
- 7.3k
- フォーク
- 827
- 平均マージ
- 21時間 35分
- マージ済み PR(30日)
- 60
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
google/error-prone のほかの issue
-
ASTHelpers.getSymbol returns null for a parenthesized expression, while javac's TreeInfo.symbol returns the symbol inside対応中かも @vlsi が 8 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
google/error-prone#6223 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
google/error-prone#6216 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
google/error-prone#6215 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
google/error-prone#6214 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
google/error-prone#6213 ·
メンテナーはふだん 1 日以内に返信
google/error-prone の issue をすべて見る
似ている issue
-
pending:code-area pending:issue-category to-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
area:core bug priority:p2
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
aomarai/minecraft-mcp#247 ·
メンテナーはふだん 1 日以内に返信
-
help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
antonyrag/ragleap-core#1062 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
projectnessie/nessie#13256 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
Vakore/ZappierGames#232 ·