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

Java record types being formatted incorrectly #966

Open
Naros opened this issue Feb 21, 2025 · 2 comments
Open

Java record types being formatted incorrectly #966

Naros opened this issue Feb 21, 2025 · 2 comments
Labels

Comments

@Naros
Copy link

Naros commented Feb 21, 2025

Describe the bug
After upgrading to 2.25.0, all Java record types are being reformatted.

For example, given the following record declaration:

public record FirstHeader(int totalBytes, int offset, int size, OffsetStatus status) {
    public boolean hasData() {
        return status == OffsetStatus.MORE_DATA_NEW_OFFSET || offset > 0;
    }
}

After running the formatted, the output yields:

public record FirstHeader(int totalBytes,int offset,int size,OffsetStatus status){

public boolean hasData(){return status==OffsetStatus.MORE_DATA_NEW_OFFSET||offset>0;}}

What is being lost here are the following:

  • Indentation to match the same indentation observed inside classes
  • Spaces after commas in the record's definition
  • Spaces before { at the end of of declaration and methods
  • Spaces before and after operators like ||, ==, >.

Expected behavior

When the record is formatted using 2.24.1, we observe the correct formatting. But once we upgraded to 2.25.0, I've observed these differences. I've reviewed all formatter configuration settings that include "record" in their names, setting their values as follows:

<profiles version="12">
  <profile kind="CodeFormatterProfile" name="Debezium" version="12">
        <!-- Various other settings -->
        <setting id="org.eclipse.jdt.core.formatter.alignment_for_record_components" value="16"/>
        <setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration" value="16"/>
        <setting id="org.eclipse.jdt.core.formatter.brace_position_for_record_constructor" value="end_of_line"/>
        <setting id="org.eclipse.jdt.core.formatter.brace_position_for_record_declaration" value="end_of_line"/>
        <setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_record_header" value="true"/>
        <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_record_components" value="insert"/>
        <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_record_declaration" value="do not insert"/>
        <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_record_declaration" value="do not insert"/>
        <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_record_components" value="insert"/>
        <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_constructor" value="insert"/>
        <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_declaration" value="insert"/>
        <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_record_declaration" value="do not insert"/>
        <setting id="org.eclipse.jdt.core.formatter.keep_record_constructor_on_one_line" value="one_line_never"/>
        <setting id="org.eclipse.jdt.core.formatter.keep_record_declaration_on_one_line" value="one_line_never"/>
        <setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_record_declaration" value="common_lines"/>
  </profile>
</profiles>

Despite those settings, the formatting with 2.25.0 is completely different than 2.24.1.

After performing a git bisect, the offending commit is df94a38 but these changes do not seem related to Java record types.

@Naros Naros added the bug label Feb 21, 2025
@Naros
Copy link
Author

Naros commented Mar 10, 2025

Any update on this?

@hazendaz
Copy link
Member

I ran a test on record class by putting your class into the build. It formatted without any issue. Our tests run 2 times to shake out any after affects, it worked fine on both so not sure what the issue is you are having.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants