shortenFullyQualifiedTypes corrupts method references on fields (x.field::m -> bogus import x.field)
Los mantenedores suelen responder en 1 día
Ya se ha fusionado un pull request relacionado.
- #3134 de @maxandersen — fusionado
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- java
- Área
- build-system
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Java
- Estrellas
- 5.7k
- Forks
- 565
- Merge medio
- 2 d 14 h
- PR fusionados (30 d)
- 66
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de diffplug/spotless
-
google-java-format 1.37.0: NoSuchMethodError on JavaFormatterOptions$Style.valueOf (Style is now a record)Posiblemente ocupada @Goooler la tomó hace 7 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
diffplug/spotless#3126 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Add support for org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_record_parameterAbierto
Dificultad 3/5 1-2 días Aptitud para principiantes 67/100
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
diffplug/spotless#3067 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de diffplug/spotless
Issues similares
-
`GET /v1/event/token/{uuid}` can report a BOM upload as done before policy evaluation and metrics have finishedPosiblemente ocupada @Zargath la tomó hoy. Abiertodefect in triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
DependencyTrack/dependency-track#7646 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
floci-io/floci#5425 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
objectionary/eo-graphs#80 ·
-
WebMvcStreamableServerTransportProvider: idle-session eviction stops permanently after a NullPointerException when a session is deleted mid-sweepPosiblemente ocupada @lejuho la tomó hoy. Abiertostatus: waiting-for-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
spring-projects/spring-ai#7133 ·
Los mantenedores suelen responder en 6 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
objectionary/jucs#141 ·
Los mantenedores suelen responder en 1 día