DuplicateBranches misses duplicate ternary branches when one branch is parenthesized
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 72/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- java
- 领域
- testing-qa
调研方向
找到 DuplicateBranches 检查及其分支比较,然后阅读它如何处理 ParenthesizedTree 和 ASTHelpers.stripParentheses。使用 issue 中的两个三元表达式示例添加或更新回归测试。两个示例都各自产生一个发现结果,且相关检查的测试通过,即为完成。
由索引模型根据 Issue 内容生成。
描述
Error Prone version
Error Prone 2.49.0 (javac 21.0.8, --source/--target 21)
Affected checks
DuplicateBranches
Description
Adding redundant parentheses around one branch of a conditional expression causes DuplicateBranches to miss duplicate branches. The check reports true ? 1 * 5 : 1 * 5, but does not report true ? 1 * 5 : (1 * 5), even though the two branches still compute the same expression.
Per JLS §15.8.5, parentheses around an expression do not change its value, type, or constant-expression status. Parenthesizing one branch should therefore not change whether the branches are considered duplicates.
I verified the following pair on Error Prone 2.49.0:
| Check | Rewrite | BEFORE | AFTER | Effect |
|---|---|---|---|---|
DuplicateBranches |
1 * 5 → (1 * 5) in one branch |
1 | 0 | false negative |
The branch comparison appears not to look through ParenthesizedTree. A possible fix is to unwrap the branch expressions before comparing them, for example with ASTHelpers.stripParentheses.
Reproducers
DuplicateBranches — (1 * 5) defeats the branch comparison
The two ternary branches remain identical; only one is parenthesized.
// BEFORE — 1 finding
public class Sample {
int x;
void m() { x = true ? 1 * 5 : 1 * 5; }
}
// AFTER — 0 findings
public class Sample {
int x;
void m() { x = true ? 1 * 5 : (1 * 5); }
}
Expected behavior
Both versions should produce 1 DuplicateBranches finding. The two ternary branches remain duplicates when one of them is enclosed in redundant parentheses.
Actual behavior
The BEFORE version produces 1 finding. The AFTER version produces 0 findings after the false branch 1 * 5 is parenthesized.
- 主要语言
- Java
- 星标
- 7.3k
- 派生
- 830
- 平均合并
- 18 小时 31 分钟
- 30 天内合并 PR
- 61
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
google/error-prone 的其他 Issue
-
ASTHelpers.getSymbol returns null for a parenthesized expression, while javac's TreeInfo.symbol returns the symbol inside可能已有人在做 @vlsi 于 11 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
google/error-prone#6223 ·
维护者通常 1 天内回复
-
InlineTrivialConstant misses an empty-string constant with a parenthesized initializer可能已有人在做 @Youssef-Khogaly 于 11 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
google/error-prone#6217 · 1 条评论 ·
维护者通常 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
-
难度 2/5 1-3 小时 新手友好度 72/100
intellij-elixir/intellij-elixir#4585 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
MetricsHub/metricshub-community#1474 ·
维护者通常 1 天内回复
-
Booking links: POST /api/booking-links with a null element in "availabilityRules" throws NullPointerException and answers 500 instead of 400可能已有人在做 @chibenwa 今天认领。 未关闭ai-driven-fuzzing bug claude Minor
难度 2/5 1-3 小时 新手友好度 72/100
linagora/twake-calendar-side-service#1322 · 1 条评论 ·
维护者通常 1 天内回复
-
PathnameExpander incorrectly interprets regex metacharacters in wildcard patterns可能已有人在做 @jiteshkhatri11 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
javapathfinder/jpf-core#662 · 1 条评论 ·
维护者通常 1 天内回复
-
3.x: `NullPointerException` ("Null 'propertyType' passed") deserializing raw `Map.Entry` with a `Shape.POJO` config override可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
FasterXML/jackson-databind#6366 ·
维护者通常 1 天内回复