Soundness: a local variable with a constant's name shadows the constant (Format.JPG read as local JPG)
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Issue で特定されている RefinementTypeChecker.visitCtFieldRead から始め、提供されている Java の例で名前の衝突を再現してください。コンテキスト検索が、ローカル変数と読み取られているフィールドをどのように区別しているかを確認してください。Issue では候補となる修正が説明されており、347 個のテストがすべてパスすると報告されています。onlyPng(g) で再現コードが refinement エラーを報告し、テストスイートも引き続きパスすれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Description
A field read of a constant such as Format.JPG is resolved to a local variable with the same simple name (JPG), if one is in scope, instead of the constant. The refinement of the local is then used, so real violations are accepted.
Minimal reproducer
import liquidjava.specification.Refinement;
public class Repro {
enum Format { JPG, PNG }
static void onlyPng(@Refinement("_ == Format.PNG") Format f) {}
public static void main(String[] args) {
Format JPG = Format.PNG; // a local that happens to share the constant's name
Format g = Format.JPG; // the enum constant JPG, not the local
onlyPng(g); // expected error: g is JPG
}
}
Expected
A refinement error at onlyPng(g): g holds Format.JPG.
Actual
Correct! Passed Verification.
Removing the line Format JPG = Format.PNG; gives the expected error (g == JPG is not a subtype of g == Format.PNG), so the name clash is what hides it.
Reproduced on main at fbfb4e23.
Where
RefinementTypeChecker.visitCtFieldRead: its first branch looks the field up by simple name in the context (where the local lives) without checking that the variable found is the field being read. A candidate fix (about 5 lines, found during the review of #319) only uses the context variable when it really is that field, and otherwise falls through; it keeps all 347 tests passing.
Context
Found by the adversarial review of #319 (fix for #302): with #319 the same clash inside an if condition (if (f == Format.JPG)) turns a former crash into an accepted violation, so this should be fixed before or with #319.
- 主要言語
- Java
- スター
- 67
- フォーク
- 36
- 平均マージ
- 4日 17時間
- マージ済み PR(30日)
- 7
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
liquid-java/liquidjava のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
liquid-java/liquidjava#323 ·
メンテナーはふだん 2 日以内に返信
-
bug
難易度 3/5 1〜2日 初心者へのやさしさ 76/100
liquid-java/liquidjava#322 ·
メンテナーはふだん 2 日以内に返信
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
liquid-java/liquidjava#318 ·
メンテナーはふだん 2 日以内に返信
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
liquid-java/liquidjava#317 ·
メンテナーはふだん 2 日以内に返信
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 62/100
liquid-java/liquidjava#316 ·
メンテナーはふだん 2 日以内に返信
liquid-java/liquidjava の issue をすべて見る
似ている issue
-
Update license yearオープン0 - Backlog 1 - Ready documentation good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
cbor
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
FasterXML/jackson-dataformats-binary#844 ·
メンテナーはふだん 1 日以内に返信
-
improvement
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apache/iceberg#18351 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
repowise-dev/repowise#2945 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Interpolating settings.xml can lead to malformed XML when variable value contains double-hyphenオープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
apache/maven#13321 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信