shortenFullyQualifiedTypes can change type resolution for inherited nested types
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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 typeTypeChild, which extendsBaseexternal.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
- Dominant language
- Java
- Stars
- 5.7k
- Forks
- 563
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 51
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from diffplug/spotless
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
diffplug/spotless#3125 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Maintainers usually reply within 1 day
All issues in diffplug/spotless
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
aoqia194/leaf-loader#19 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
apache/streampark#4521 ·
-
Update license yearOpen0 - Backlog 1 - Ready documentation good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
cbor
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
FasterXML/jackson-dataformats-binary#844 ·
Maintainers usually reply within 1 day
-
Issue: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
OpenAPITools/openapi-generator#25107 ·
Maintainers usually reply within 1 day