Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indentation level difference after case between Java 11 and 17 #643

Closed
pburka opened this issue Aug 12, 2021 · 1 comment · Fixed by #654
Closed

Indentation level difference after case between Java 11 and 17 #643

pburka opened this issue Aug 12, 2021 · 1 comment · Fixed by #654

Comments

@pburka
Copy link

pburka commented Aug 12, 2021

The 1.11.0 formatter running on a Java 17 JDK indents some lines further than the same formatter running on a Java 11 JDK. The problem can be seen with long expressions in switch cases.

Input file:

public class Foo {
    static final int VERBOSE_WORDY_AND_LENGTHY_ONE = 1;
    static final int VERBOSE_WORDY_AND_LENGTHY_TWO = 2;
    static final int VERBOSE_WORDY_AND_LENGTHY_FOUR = 4;
    
    public static int fn(int x) {
        switch (x) {
        case VERBOSE_WORDY_AND_LENGTHY_ONE | VERBOSE_WORDY_AND_LENGTHY_TWO | VERBOSE_WORDY_AND_LENGTHY_FOUR:
            return 0;
        default:
            return 1;
        }
    }
}

Java 11 format: (build 11.0.9.1+1)

public class Foo {
  static final int VERBOSE_WORDY_AND_LENGTHY_ONE = 1;
  static final int VERBOSE_WORDY_AND_LENGTHY_TWO = 2;
  static final int VERBOSE_WORDY_AND_LENGTHY_FOUR = 4;

  public static int fn(int x) {
    switch (x) {
      case VERBOSE_WORDY_AND_LENGTHY_ONE
          | VERBOSE_WORDY_AND_LENGTHY_TWO
          | VERBOSE_WORDY_AND_LENGTHY_FOUR:
        return 0;
      default:
        return 1;
    }
  }
}

(10 spaces before each |)

Java 17 format: (build 17-ea+31-2664)

public class Foo {
  static final int VERBOSE_WORDY_AND_LENGTHY_ONE = 1;
  static final int VERBOSE_WORDY_AND_LENGTHY_TWO = 2;
  static final int VERBOSE_WORDY_AND_LENGTHY_FOUR = 4;

  public static int fn(int x) {
    switch (x) {
      case VERBOSE_WORDY_AND_LENGTHY_ONE
              | VERBOSE_WORDY_AND_LENGTHY_TWO
              | VERBOSE_WORDY_AND_LENGTHY_FOUR:
        return 0;
      default:
        return 1;
    }
  }
}

(14 spaces before each |)

The indentation is similarly inconsistent with or without the -a flag.

copybara-service bot pushed a commit that referenced this issue Aug 25, 2021
Fixes #643

PiperOrigin-RevId: 392567001
@pburka
Copy link
Author

pburka commented Oct 19, 2021

Given that Java 17 has been GA for over a month now, any chance of a new GJF release that's Java 17 compatible?

fawind pushed a commit to palantir/palantir-java-format that referenced this issue Jan 7, 2022
fawind pushed a commit to palantir/palantir-java-format that referenced this issue Jan 7, 2022
fawind pushed a commit to palantir/palantir-java-format that referenced this issue Jan 7, 2022
fawind pushed a commit to palantir/palantir-java-format that referenced this issue Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant