Skip to content

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

Description

@pburka

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.

Activity

  1. pburka commented on Oct 19, 2021

    @pburka
    Author

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

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