Skip to content

Conversation

@crogoz
Copy link
Contributor

@crogoz crogoz commented Oct 13, 2025

Before this PR

Checkstyle requires Java files to end with a new line see here.

After this PR

We are now enforcing this through the formatter directly.
Fixed a bug where Bootstrapping/NativeImageFormatter were incorrectly reading the input range as a 1-index vs 0-index.

==COMMIT_MSG==
Java files always end with a new line
==COMMIT_MSG==

Possible downsides?

@changelog-app
Copy link

changelog-app bot commented Oct 13, 2025

Generate changelog in changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

Java files always end with a new line

Check the box to generate changelog(s)

  • Generate changelog entry

@changelog-app
Copy link

changelog-app bot commented Oct 13, 2025

Successfully generated changelog entry!

What happened?

Your changelog entries have been stored in the database as part of our migration to ChangelogV3.

Need to regenerate?

Simply interact with the changelog bot comment again to regenerate these entries.

Comment on lines +387 to +388
// Ensure the file ends with a newline
builder.forcedBreak();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we write a test for this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also perhaps the multiple lines at the end of the file case

@crogoz
Copy link
Contributor Author

crogoz commented Oct 13, 2025

Adding do not merge, the Intellij plugin seems to ignore the last lines when returing the list of replacements. Investigating now why that is the case.

case "--character-range":
case "-character-range":
parseRangeSet(optionsBuilder.characterRangesBuilder(), getValue(flag, it, value));
parseCharacterRanges(optionsBuilder.characterRangesBuilder(), getValue(flag, it, value));
Copy link
Contributor Author

@crogoz crogoz Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug from the beginning of pjf. parseRangeSet expects a 1-indexed range, but we have a 0-indexed range (see RnageUtils class).

This would mean that Intellij only (./gradlew spotless would work correclty as it doesn't use the same getReplacements workflow) would not reformat the full file eg. after formatting the "format.input" file, we'd get a truncated version of the formatted output:

Screenshot 2025-10-14 at 5 30 11 PM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find!

}
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intentionally removing the last line to make sure we are getting the error seen in: https://github.com/palantir/palantir-java-format/pull/1433/files#r2429564482

@crogoz crogoz requested a review from CRogers October 14, 2025 15:33
Copy link
Contributor

@CRogers CRogers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, should remove this toil for devs. I checked as well and intellij will format after making a new file, so this is immediately correct.

@bulldozer-bot bulldozer-bot bot merged commit cb702ea into develop Oct 15, 2025
7 checks passed
@bulldozer-bot bulldozer-bot bot deleted the cr/new-line-java-files branch October 15, 2025 11:47
@autorelease3
Copy link

autorelease3 bot commented Oct 15, 2025

Released 2.79.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants