shortenFullyQualifiedTypes corrupts method references on fields (x.field::m -> bogus import x.field)
維護者通常 1 天內回覆
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 25/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 停滯
- 技術堆疊
- java
- 領域
- build-system
研究方向
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.
由索引模型根據 Issue 內容生成。
描述
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.
- 主要語言
- Java
- 星號
- 5.7k
- 分支
- 565
- 平均合併
- 2 天 2 小時
- 30 天內合併 PR
- 57
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
diffplug/spotless 的其他 Issue
-
google-java-format 1.37.0: NoSuchMethodError on JavaFormatterOptions$Style.valueOf (Style is now a record)可能已有人在做 @Goooler 於 4 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
diffplug/spotless#3126 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 65/100
diffplug/spotless#3125 · 2 則留言 ·
維護者通常 1 天內回覆
-
Add support for org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_record_parameter未關閉
難度 3/5 1-2 天 新手友好度 67/100
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 68/100
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 35/100
維護者通常 1 天內回覆
查看 diffplug/spotless 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 88/100
java-native-access/jna#1740 ·
-
難度 1/5 1 小時以內 新手友好度 82/100
-
難度 1/5 1 小時以內 新手友好度 88/100
portfolio-performance/portfolio#6119 ·
維護者通常 8 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
jenkinsci/ec2-plugin#2041 ·
-
L: github:actions L: php:composer
難度 2/5 1-3 小時 新手友好度 88/100
dependabot/dependabot-core#16493 ·
維護者通常 1 天內回覆