Skip to content

The greclipse formatter changes the line separator unconditionally, breaking subsequent executions of the java formatter on Windows #1049

Closed as not planned
@basil

Description

@basil
  • Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
  • Java version: 1.8.0_312, vendor: Private Build, runtime: /usr/lib/jvm/java-8-openjdk-amd64/jre
  • Spotless 2.17.7

Observed in jenkinsci/jenkins#6104 when trying to add greclipse formatting to a Maven multi-module project with the java formatter already enabled. The checks started failing on Windows but kept passing on Linux.

I looked into how this was working before adding greclipse. The java formatter was working fine on both Linux and Windows; in Formatter#computeLineEndings, lineEndingsPolicy.getEndingFor(file) was returning \n on Linux and \r\n on Windows as expected.

After adding greclipse to the Maven multi-module project, the behavior continued to be as expected until the greclipse formatter ran. During its execution, it got to

/**
* In case the string which will be formatted does not contain any
* line delimiter (single line), Eclipse falls back to use the
* system property.
* Change the system default to the UNIX line separator as required
* by Spotless.
* @throws ServiceException in case service has already been configured
*/
default public void changeSystemLineSeparator() throws ServiceException {
System.setProperty("line.separator", LINE_DELIMITER);
}

upon which it changed the line separator to \n unconditionally for both Linux and Windows. That is as expected for greclipse's own execution, but then it never set the value back to the original value. So in a subsequent execution of the java formatter on a different Maven module, lineEndingsPolicy.getEndingFor(file) started returning \n on Windows (not expected) and the Windows build failed with hundreds of errors like

Failed to execute goal com.diffplug.spotless:spotless-maven-plugin:2.17.7:check (default) on project jenkins-core: The following files had format violations:
    src\main\java\hudson\ClassicPluginStrategy.java
        @@ -1,720 +1,720 @@
        -/*\r\n
        - * The MIT License\r\n
        - * \r\n

The greclipse formatter should set the line ending back to the original value when it is done.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions