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

InlineTrivialConstant misses an empty-string constant with a parenthesized initializer

Đang mở Phù hợp với người mới
#6,217 1 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

@Youssef-Khogaly đang làm issue này rồi.

Từ ngày 21/10/2026.

  • #6222 của @Youssef-Khogaly — đang mở

Đá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

Bắt đầu với matcher InlineTrivialConstant và kiểm tra xem việc so khớp phần khởi tạo có xử lý ParenthesizedTree hay không; issue gợi ý ASTHelpers.stripParentheses làm manh mối. So sánh các ví dụ được báo cáo và các ví dụ chuỗi rỗng bị bỏ sót với những bài kiểm tra hiện có cho kiểm tra này. Hoàn tất khi cả hai phần khởi tạo đều tạo ra một phát hiện và các bài kiểm tra của kiểm tra này đề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

InlineTrivialConstant

Description

Adding redundant parentheses around an empty-string initializer causes InlineTrivialConstant to miss a trivial constant. The check reports private static final String EMPTY = "";, but does not report private static final String EMPTY = ("");.

Per JLS §15.8.5, parentheses around an expression do not change its value, type, or constant-expression status. The parenthesized empty string is still the same trivial constant.

I verified the following pair on Error Prone 2.49.0:

Check Rewrite BEFORE AFTER Effect
InlineTrivialConstant "" → ("") 1 0 false negative

The matcher appears to inspect the initializer without looking through ParenthesizedTree. A possible fix is to unwrap the initializer before matching it, for example with ASTHelpers.stripParentheses.

Reproducers
InlineTrivialConstant — ("") is missed
// BEFORE — 1 finding
public class Sample {
  private static final String EMPTY = "";
}
// AFTER — 0 findings
public class Sample {
  private static final String EMPTY = ("");
}
Expected behavior

Both versions should produce 1 InlineTrivialConstant finding. Adding redundant parentheses around the empty-string initializer does not change its value or constant-expression status.

Actual behavior

The BEFORE version produces 1 finding. The AFTER version produces 0 findings after the empty-string initializer 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.