DuplicateBranches misses duplicate ternary branches when one branch is parenthesized
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 72/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- java
- Lĩnh vực
- testing-qa
Hướng nghiên cứu
Tìm kiểm tra DuplicateBranches và phần so sánh các nhánh của nó, sau đó đọc cách kiểm tra xử lý ParenthesizedTree và ASTHelpers.stripParentheses. Thêm hoặc cập nhật một bài kiểm thử hồi quy sử dụng hai ví dụ toán tử ba ngôi trong issue. Công việc hoàn tất khi cả hai ví dụ đều tạo ra một phát hiện và các bài kiểm thử liên quan của kiểm tra đều đạt.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Java
- Star
- 7.3k
- Fork
- 827
- Merge trung bình
- 21 giờ 35 phút
- Pull request đã merge (30 ngày)
- 60
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của google/error-prone
-
ASTHelpers.getSymbol returns null for a parenthesized expression, while javac's TreeInfo.symbol returns the symbol insideCó thể đã có người làm @vlsi đã nhận 9 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
google/error-prone#6223 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
InlineTrivialConstant misses an empty-string constant with a parenthesized initializerCó thể đã có người làm @Youssef-Khogaly đã nhận 9 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
google/error-prone#6217 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
google/error-prone#6215 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
NonAtomicVolatileUpdate misses volatile increments and decrements with parenthesized operandsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
google/error-prone#6214 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
google/error-prone#6213 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của google/error-prone
Issue tương tự
-
[BUG] micronaut-serde-oracle-jdbc-json brings a second OJDBC driver onto the runtime classpathCó thể đã có người làm @ZARAYACH đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
micronaut-projects/micronaut-serialization#1494 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Maintainer thường phản hồi trong vòng 2 ngày
-
code-health feature/sync OS/Android QA/Test-Plan-Specified QA/Yes
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
brave/brave-browser#60327 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Type: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
it-at-m/raumreservierung#383 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
aws/context-ontology-accelerator#325 ·
Maintainer thường phản hồi trong vòng 1 ngày