Skip to content

Leading comment after an opening delimiter is hoisted out of its group #171

Closed

Description

@abashev

Upstream: google/google-java-format#1501
Kind: bug | Priority: low

google-java-format#1501 (merged 2026-10-29, copybara export; groundwork in google-java-format#1500 and baseline tests in google-java-format#1502) fixes comments placed right after an opening token being pulled out of the indented group, leaving the comment and the next line unindented. Cases covered: assert with a detail message, the semicolon after enum constants, for initializers, multi-resource try headers, multi-catch clauses and explicit type argument lists. After the fix such comments stay indented inside the group, for example in a for ( header the comment, int i = 0;, the condition and the update each get their own continuation-indented line.

Why it matters: it is a correctness-of-layout bug class around comments that our engine may share, since both derive from the same original visitor design.

Affected files in our repo:

  • open-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java
  • open-java-format/src/main/java/com/palantir/javaformat/doc (comment handling in the layout builder)

Suggested action: investigate. Put a comment after for ( and after try ( into our formatter and compare the indentation. Examples: not available - the pre-change output is only in the baseline test PR and I did not run our formatter.


Filed from an upstream-watch ticket after manual review.

Activity

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions