shortenFullyQualifiedTypes corrupts method references on fields (x.field::m -> bogus import x.field)
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- java
- Lĩnh vực
- build-system
Hướng nghiên cứu
Start by reading the implementation of shortenFullyQualifiedTypes() added in #3005 and the related tests; the issue does not name their file paths. Reproduce with the supplied Java example and run spotlessApply followed by compileJava. Done means catalog.aliases::get remains unchanged, no bogus import is added, and a regression test covers the case. A linked open pull request (#3134) indicates work is already underway.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
shortenFullyQualifiedTypes() (added in #3005) corrupts a method reference on a field of a local variable. It treats localVar.field::method as if localVar.field were a fully-qualified type, shortens it to field::method, and injects a bogus import localVar.field; — which does not compile.
Because it only manifests on spotlessApply (not the read-only spotlessCheck), a developer runs spotlessApply, commits, and then the project no longer builds.
Version
com.diffplug.spotless8.10.3 (Gradle plugin)- JDK 11 / 17 (reproduces on both)
Minimal reproducer
build.gradle:
plugins {
id 'java'
id 'com.diffplug.spotless' version '8.10.3'
}
repositories { mavenCentral() }
spotless { java { shortenFullyQualifiedTypes() } }
src/main/java/Example.java:
import java.util.Map;
import java.util.function.Function;
public class Example {
static class Catalog {
Map<String, String> aliases;
}
String demo(Catalog catalog) {
return find(catalog.aliases::get); // method ref on a field of a local var
}
String find(Function<String, String> f) {
return f.apply("x");
}
}
Steps
./gradlew spotlessApply
./gradlew compileJava
Actual
spotlessApply rewrites the file to:
import java.util.Map;
import java.util.function.Function;
import catalog.aliases; // <-- bogus import of a non-existent package/type
public class Example {
...
String demo(Catalog catalog) {
return find(aliases::get); // <-- qualifier dropped, now unresolved
}
...
}
and compilation fails:
Example.java: error: package catalog does not exist
Expected
catalog.aliases::get is a method reference on a field access of a local variable, not a fully-qualified type reference. It must be left untouched (no shortening, no import added).
Root cause (guess)
The qualifier-resolution doesn't verify that the left-hand side of a qualified name / method-reference scope actually resolves to a type before shortening. Field accesses on locals/params (x.y, x.y::m, x.y.z) are being misclassified as fully-qualified type names. Checking that the qualifier is a type (not a local variable / field expression) before rewriting should fix it.
Found while enabling the step on a real codebase (jbangdev/jbang), where catalog.aliases::get (a Catalog local + Map field) broke the build.
- Ngôn ngữ chính
- Java
- Star
- 5.7k
- Fork
- 565
- Merge trung bình
- 2 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 57
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- 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 diffplug/spotless
-
google-java-format 1.37.0: NoSuchMethodError on JavaFormatterOptions$Style.valueOf (Style is now a record)Có thể đã có người làm @Goooler đã nhận 4 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
diffplug/spotless#3126 · 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 65/100
diffplug/spotless#3125 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add support for org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_record_parameterĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 67/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của diffplug/spotless
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
java-native-access/jna#1740 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
portfolio-performance/portfolio#6119 ·
Maintainer thường phản hồi trong vòng 8 ngày
-
Bump up AWS SDK to 2.54.3Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
jenkinsci/ec2-plugin#2041 ·
-
L: github:actions L: php:composer
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
dependabot/dependabot-core#16493 ·
Maintainer thường phản hồi trong vòng 1 ngày