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 天 4 小时
- 30 天内合并 PR
- 58
环境准备
- 没有 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 天内回复
-
ktfmt changes groupId to "org.jetbrains" starting with version 0.65可能已有人在做 @Goooler 今天认领。 未关闭
难度 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
-
waiting-for-triage
难度 1/5 1 小时以内 新手友好度 72/100
spring-cloud/spring-cloud-openfeign#1443 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 84/100
ADORSYS-GIS/keycloak-oid4vp-plugin#221 ·
维护者通常 2 天内回复
-
status: team-only type: dependency-upgrade
难度 2/5 1-3 小时 新手友好度 65/100
spring-projects/spring-boot#52099 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 67/100
tchiotludo/akhq#3307 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
objectionary/jeo-maven-plugin#1885 ·
维护者通常 4 天内回复