Skip to content

expandWildcardImports issue for maven multi module projects #2946

Open

Description

@pdeneve

When using expandWildcardImports, mvn spotless:apply fails for maven multi module projects with the following error:

[ERROR] Failed to execute goal com.diffplug.spotless:spotless-maven-plugin:3.5.1:apply (default-cli) on project two: There were 1 lint error(s), they must be fixed or suppressed.
[ERROR]   src/main/java/two/Two.java:LINE_UNDEFINED expandwildcardimports(java.lang.IllegalStateException) Symbol resolution not configured: to configure consider setting a SymbolResolver in the ParserConfiguration (...)
[ERROR]   Resolve these lints or suppress with `<lintSuppressions>`

To reproduce:

git clone https://github.com/pdeneve/spotless-expand-wildcard-imports-issue.git
cd spotless-expand-wildcard-imports-issue
mvn spotless:apply

Spotless maven plugin version used = 3.5.1

Activity

  1. Pankraz76 commented on Nov 7, 2026

    @Pankraz76

    Thanks for the report and the minimal reproducer @pdeneve, that made this quick to track down!

    The multi-module setup turned out to be incidental. The real trigger is that Two.java is a record. expandWildcardImports created its JavaParser at the library's default language level (Java 11), where records fail validation. JavaParser still returns a compilation unit in that case, but it only attaches the symbol resolver to successful parses, hence Symbol resolution not configured. Any wildcard import in a file using post-Java-11 syntax (records, sealed types, pattern-matching switches, …) would hit this, single-module too.

    The fix parses at JavaParser's newest language level (the same one its JavaParserTypeSolver already uses for source roots). It also leaves a file unchanged instead of crashing if it still can't be parsed cleanly. A regression test mirrors your reproducer (module two depending on one, record Two(LocalDate date) with import java.time.*;). It failed with exactly your error before the change and passes after.

    Fix: #3173

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions