Soundness: a local variable with a constant's name shadows the constant (Format.JPG read as local JPG)
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 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 小时
- 30 天内合并 PR
- 7
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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
-
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
OpenConext/OpenConext-access#1015 ·
维护者通常 1 天内回复
-
68000: FDBcc branch target is 2 bytes too low (uses inst_start+2 instead of the displacement word)未关闭
难度 2/5 1-3 小时 新手友好度 82/100
NationalSecurityAgency/ghidra#9702 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
apache/rocketmq-dashboard#5358 ·
维护者通常 3 天内回复
-
area:cpan-port area:database bug
难度 2/5 1-3 小时 新手友好度 84/100
fglock/PerlOnJava#1605 ·
维护者通常 1 天内回复