question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong formatting (missing whitespace) in Java instanceof type pattern with method calls on the left side

See original GitHub issue

If you are submitting a bug, please include the following:

  • summary of problem
  • gradle or maven version
  • spotless version
  • operating system and version
  • copy-paste your full Spotless configuration block(s), and a link to a public git repo that reproduces the problem if possible
  • copy-paste the full content of any console errors emitted by gradlew spotless[Apply/Check] --stacktrace

We still use Spotless 5.15.0 because all subsequent releases introduce an issue that we are affected: a whitespace before instanceof is removed in some cases, not all.

We use Gradle 7.3.3 and a custom Eclipse configuration: https://github.com/ls1intum/Artemis/blob/develop/artemis-spotless-style.xml (Note: In Eclipse, it seems the formatting works correctly for the example that went wrong in our repository)

Our full gradle file is here: https://github.com/ls1intum/Artemis/blob/develop/build.gradle

Here is the relevant spotless configuration:

spotless {
    // allows to execute the code formatting commands ./gradlew spotlessApply and ./gradlew spotlessCheck
    java {
        target project.fileTree(project.rootDir) {
            include "**/*.java"
            exclude "**/src/main/java/de/tum/in/www1/artemis/service/connectors/BambooService.java", "**/src/main/java/de/tum/in/www1/artemis/config/SecurityConfiguration.java", "**/src/main/java/de/tum/in/www1/artemis/config/SAML2Configuration.java", "**/src/test/resources/test-data/repository-export/EncodingISO_8559_1.java", "**/node_modules/**", "**/out/**", "**/repos/**", "**/build/**", "**/src/main/generated/**", "**/src/main/resources/templates/**"
        }
        importOrderFile "artemis-spotless.importorder"
        eclipse().configFile "artemis-spotless-style.xml"

        removeUnusedImports()
    }
}

When I update to the latest spotless version in line 24 of build.gradle

id "com.diffplug.spotless" version "6.0.5"

then using ./gradlew spotlessApply -x webapp will lead to changes that are wrong:

0001-wrong-spotless-changes-git-patch.txt

Here is one simple example:

-                    if (discoveryHealthContributor.getContributor() instanceof HealthIndicator healthIndicator) {
+                    if (discoveryHealthContributor.getContributor()instanceof HealthIndicator healthIndicator) {

Notice the removed whitespace between the method call on the left side and instanceof.

It seems that a method call on the left side of the Java instanceof type pattern is not handled correctly, because it works correctly if the left side is a normal variable.

I went through all Eclipse Code Style settings and could not find an appropriate setting for a whitespace between a method call and instanceof.

My OS version is macOS 12.1, but it seems this is independent of the OS

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
nedtwiggcommented, Jan 6, 2022

Looks like this will get fixed when #1059 gets fixed.

0reactions
nedtwiggcommented, Dec 23, 2021

Do you know if the Eclipse developers are already aware of this issue? Or should we open an issue in their bug tracking system?

I don’t know if they are already aware, and if they aren’t it would be a good idea to open an issue with them. If you find anything interesting at https://bugs.eclipse.org/bugs/ feel free to post it back here. Spotless integrates with lots of formatters. We don’t take responsibility for their bugs, but we are happy to keep issues such as this open so that people can track/coordinate.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TSLint get rid of missing-whitespace - Stack Overflow
This error message comes from the whitespace rule. I believe the rule wants you to add a space either before or after (not...
Read more >
Code Style. Java | IntelliJ IDEA Documentation - JetBrains
In this field, specify the number of spaces to be inserted between the elements of an array, in expressions, method declarations and method...
Read more >
Bug Patterns - Error Prone
Incompatible type as argument to Object-accepting Java collections method. CollectionToArraySafeParameter. The type of the array parameter of Collection.
Read more >
Escape Sequences in Java - GeeksforGeeks
Each escape character is a valid character literal. The list of Java escape sequences: Why will we need Escape sequence? Suppose we would...
Read more >
Coding - checkstyle
By default, the check demands a comma at the end if neither left nor ... This method is used by many of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found