Skip to content

Conversation

@jtkiesel
Copy link
Contributor

What changed with this PR:

Reverts the connection of trailing semicolon printing (in ResourceSpecification) to the trailingComma option (which was done in #731). This is a bit of an edge case, and it isn't at all intuitive that an option named trailingComma would also control whether a trailing semicolon would be printed in this case. The optional trailing semicolon will now be left as-is (printed if it exists, omitted if not), as it used to be.

Example

Input

class Example {

  void multiResourceTry() {
    try (FirstResource firstResource = new FirstResource(); SecondResource secondResource = new SecondResource()) {
      return br.readLine();
    } catch (ArithmeticException | ArrayIndexOutOfBoundsException e) {
      System.out.println("Warning: Not breaking multi exceptions");
    }
  }

  void multiResourceTryWithTrailingSemi() {
    try (
      FirstResource firstResource = new FirstResource();
      SecondResource secondResource = new SecondResource();
    ) {
      return br.readLine();
    } catch (ArithmeticException | ArrayIndexOutOfBoundsException e) {
      System.out.println("Warning: Not breaking multi exceptions");
    }
  }
}

Output

class Example {

  void multiResourceTry() {
    try (
      FirstResource firstResource = new FirstResource();
      SecondResource secondResource = new SecondResource()
    ) {
      return br.readLine();
    } catch (ArithmeticException | ArrayIndexOutOfBoundsException e) {
      System.out.println("Warning: Not breaking multi exceptions");
    }
  }

  void multiResourceTryWithTrailingSemi() {
    try (
      FirstResource firstResource = new FirstResource();
      SecondResource secondResource = new SecondResource();
    ) {
      return br.readLine();
    } catch (ArithmeticException | ArrayIndexOutOfBoundsException e) {
      System.out.println("Warning: Not breaking multi exceptions");
    }
  }
}

Relative issues or prs:

Closes #750

@jtkiesel jtkiesel merged commit 38bfc37 into jhipster:main Jul 31, 2025
6 checks passed
@jtkiesel jtkiesel deleted the fix/trailing-semi branch July 31, 2025 20:37
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 this pull request may close these issues.

Wrapped try-with-resources resource declaration gets unnecessary added semicolon

1 participant