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

shortenFullyQualifiedTypes can change type resolution for inherited nested types

Đang mở
#3,117 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ó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
52/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
tooling

Hướng nghiên cứu

Start with the shortenFullyQualifiedTypes() implementation and reproduce the issue using the linked Gradle project and ./gradlew spotlessApply. Trace how inherited nested types affect shortening decisions, then verify that the qualified external.Type reference remains safe and the formatted project still compiles.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

shortenFullyQualifiedTypes can change the meaning of a qualified type when the simple name is also an inherited nested type.

The formatter avoids some collisions with types declared in the same compilation unit, but does not appear to account for member types inherited from a superclass or interface.

Reproducer

Spotless Gradle plugin 8.10.3, with shortenFullyQualifiedTypes() as the only configured Java step:

The complete Gradle project is available here:

https://gist.github.com/MattAlp/a50100bc9d712c470ded424c36e8f315

The reproducer contains:

  • Base, which declares nested type Type
  • Child, which extends Base
  • external.Type, which is referenced by fully qualified name

Before formatting, Child contains:

public static String use(external.Type value) {
    return value.externalOnly();
}

The project compiles successfully. After running:

./gradlew spotlessApply

Spotless adds import external.Type; and changes the code to:

public static String use(Type value) {
    return value.externalOnly();
}

The unqualified Type resolves to the inherited Base.Type, not external.Type. Compilation then fails:

cannot find symbol
  method externalOnly()
  location: variable value of type Type

Suggested behavior

Leave a qualified reference alone when its simple name can resolve to an inherited member type. If this cannot be determined without a classpath, the conservative behavior should be to leave the qualification intact.

Related work

This appears related to:

  • #3033 — same-compilation-unit type collisions
  • #3031 — collisions with types declared in the same file
  • #3037 — preserving existing unqualified type resolution
Ngôn ngữ chính
Java
Star
5.7k
Fork
563
Merge trung bình
1 ngày 8 giờ
Pull request đã merge (30 ngày)
52

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 diffplug/spotless

Tất cả issue của diffplug/spotless

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.