Skip to content

Fix wildcard import expansion for JDK XML types#2921

Open
aKandzior wants to merge 2 commits intodiffplug:mainfrom
aKandzior:fix-expand-wildcard-jdk-xml-types
Open

Fix wildcard import expansion for JDK XML types#2921
aKandzior wants to merge 2 commits intodiffplug:mainfrom
aKandzior:fix-expand-wildcard-jdk-xml-types

Conversation

@aKandzior
Copy link
Copy Markdown

Summary

This fixes expandWildcardImports() for JDK classes outside the java.* and javax.* package prefixes, such as org.xml.sax.InputSource.

expandWildcardImports() uses JavaParser symbol resolution to inspect the whole compilation unit before replacing wildcard imports. The default ReflectionTypeSolver only covers java.* and javax.*, so JDK XML types e.g. in org.xml.sax.* could fail with an UnsolvedSymbolException.

Changes

  • Use ReflectionTypeSolver.JCL_ONLY for the reflection type solver.
  • Add a regression test with org.xml.sax.InputSource and a java.io.* wildcard import.

Test

./gradlew :testlib:test --tests com.diffplug.spotless.java.ExpandWildcardImportsStepTest --no-daemon --no-configuration-cache --console=plain

aKandzior added 2 commits May 8, 2026 14:22
expandWildcardImports uses JavaParser symbol resolution to inspect the whole compilation unit before replacing wildcard imports. The default ReflectionTypeSolver only covers java.* and javax.* APIs, so JDK classes in packages such as org.xml.sax could not be resolved.

This caused formatting to fail with an UnsolvedSymbolException when a file contained both a wildcard import and a JDK XML type such as org.xml.sax.InputSource.

Use ReflectionTypeSolver.JCL_ONLY so the resolver covers the full Java class library package set known to JavaParser, including org.xml.sax.

Adds a regression test with org.xml.sax.InputSource and a java.io.* wildcard import.

Test: ./gradlew :testlib:test --tests com.diffplug.spotless.java.ExpandWildcardImportsStepTest --no-daemon --no-configuration-cache --console=plain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant