diff --git a/CHANGES.md b/CHANGES.md index 3bb2ae6f56..d820fa667a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added - Add `javaparserVersion` option to the Cleanthat step, allowing callers to override the JavaParser version pulled in transitively by Cleanthat. ([#2903](https://github.com/diffplug/spotless/pull/2903)) ### Changes +- Fix `expandWildcardImports` failing on JDK XML types such as `org.xml.sax.InputSource`. ([#2921](https://github.com/diffplug/spotless/pull/2921)) - Bump default `cleanthat` version `2.24` -> `2.25`. ([#2903](https://github.com/diffplug/spotless/pull/2903)) - Bump default `eclipse-jdt` version from `4.35` to `4.39`. ([#2912](https://github.com/diffplug/spotless/pull/2912)) diff --git a/lib/src/javaParser/java/com/diffplug/spotless/glue/javaparser/ExpandWildcardsFormatterFunc.java b/lib/src/javaParser/java/com/diffplug/spotless/glue/javaparser/ExpandWildcardsFormatterFunc.java index fdde8eb362..d5c7dd1956 100644 --- a/lib/src/javaParser/java/com/diffplug/spotless/glue/javaparser/ExpandWildcardsFormatterFunc.java +++ b/lib/src/javaParser/java/com/diffplug/spotless/glue/javaparser/ExpandWildcardsFormatterFunc.java @@ -70,7 +70,7 @@ public ExpandWildcardsFormatterFunc(Collection typeSolverClasspath) throws this.parser = new JavaParser(); CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver(); - combinedTypeSolver.add(new ReflectionTypeSolver()); + combinedTypeSolver.add(new ReflectionTypeSolver(ReflectionTypeSolver.JCL_ONLY)); for (File element : typeSolverClasspath) { if (element.isFile()) { combinedTypeSolver.add(new JarTypeSolver(element)); diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index e939b70b70..74a7637865 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -9,6 +9,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed - Fix `tableTestFormatter` editorconfig cache not honoring `.editorconfig` changes across Gradle daemon runs due to a shared static `EditorConfigProvider`. ([#2893](https://github.com/diffplug/spotless/pull/2893)) ### Changes +- Fix `expandWildcardImports` failing on JDK XML types such as `org.xml.sax.InputSource`. ([#2921](https://github.com/diffplug/spotless/pull/2921)) - Bump default `cleanthat` version `2.24` -> `2.25`. ([#2903](https://github.com/diffplug/spotless/pull/2903)) - Bump default `eclipse-jdt` version from `4.35` to `4.39`. ([#2912](https://github.com/diffplug/spotless/pull/2912)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 70f0ec99c7..39a5c69b31 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -6,6 +6,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added - Add `` option to ``, allowing users to override the JavaParser version pulled in transitively by Cleanthat. ([#2903](https://github.com/diffplug/spotless/pull/2903)) ### Changes +- Fix `expandWildcardImports` failing on JDK XML types such as `org.xml.sax.InputSource`. ([#2921](https://github.com/diffplug/spotless/pull/2921)) - Bump default `cleanthat` version `2.24` -> `2.25`. ([#2903](https://github.com/diffplug/spotless/pull/2903)) - Bump default `eclipse-jdt` version from `4.35` to `4.39`. ([#2912](https://github.com/diffplug/spotless/pull/2912)) diff --git a/testlib/src/test/java/com/diffplug/spotless/java/ExpandWildcardImportsStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/ExpandWildcardImportsStepTest.java index c71be50bc6..723429081d 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/ExpandWildcardImportsStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/ExpandWildcardImportsStepTest.java @@ -150,6 +150,39 @@ public class Test { StepHarness.forStep(step).test(simpleCode, expectedOutput); } + @Test + void expandWildcardImports_resolvesJdkXmlTypes() throws Exception { + FormatterStep step = ExpandWildcardImportsStep.create(Collections.emptySet(), TestProvisioner.mavenCentral()); + + String simpleCode = """ + package test; + + import java.io.*; + import org.xml.sax.InputSource; + + public class Test { + InputSource inputSource(String value) { + return new InputSource(new StringReader(value)); + } + } + """; + + String expectedOutput = """ + package test; + + import java.io.StringReader; + import org.xml.sax.InputSource; + + public class Test { + InputSource inputSource(String value) { + return new InputSource(new StringReader(value)); + } + } + """; + + StepHarness.forStep(step).test(simpleCode, expectedOutput); + } + @Test void expandWildcardImports_nullSafety() throws Exception { // Test null safety