palantir / palantir-java-format

A modern, lambda-friendly, 120 character Java formatter.
Apache License 2.0
477 stars 48 forks source link

crash on white space in import statements #1124

Open mlau-anet opened 2 months ago

mlau-anet commented 2 months ago

What happened?

case a

import java. util.*;

results in

com.palantir.javaformat.java.FormatterException: error: Could not parse imported name, at:  
    at com.palantir.javaformat.java.ImportOrderer.scanImported (ImportOrderer.java:417)

case b

import java .util.*;

results in

com.palantir.javaformat.java.FormatterException: error: Expected ; after import
    at com.palantir.javaformat.java.ImportOrderer.scanImports (ImportOrderer.java:321)

What did you want to happen?

Should not crash and instead should remove the extra white space, resulting in:

import java.util.*;

env details

            <plugin>
                <groupId>com.diffplug.spotless</groupId>
                <artifactId>spotless-maven-plugin</artifactId>
                <version>2.43.0</version>
                <configuration>
                    <java>
                        <importOrder />
                        <removeUnusedImports />
                        <trimTrailingWhitespace />
                        <endWithNewline />
                        <indent>
                            <spaces>true</spaces>
                            <spacesPerTab>4</spacesPerTab>
                        </indent>
                        <palantirJavaFormat />
                    </java>
                </configuration>
            </plugin>