Skip to content

Formatter gets confused between records and annotations #4288

@alienisty

Description

@alienisty

Given the following records:

public record X(String a,
                @SuppressWarnings({ "a", "b" }) String b) {
  
}

record Y(String c){
}

and this formatter configuration

code-formatter.xml.txt

Then, if we format the above code we get the following:

public record X(String a,
                @SuppressWarnings( {  // <-- the space should not be inserted
                  "a", "b" }) String b){ // <-- the space should be inserted

}

record Y(String c) { // <-- this works just fine
}

In record X, a space has been inserted between the opening bracket of the annotation and the opening brace, where the configuration says it should not. The space is removed, instead, between the closing bracket of the record field declaration and the opening brace of its body, where the configuration says it should insert a space.
In record Y, where there are no annotations, the formatter works as expected.

Eclipse Java Development Tools 3.20.300.v20250805-1800

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