Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

DuplicateBranches misses duplicate ternary branches when one branch is parenthesized

Đang mở Phù hợp với người mới
#6,216 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của google/error-prone

Tất cả issue của google/error-prone

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.