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

Apply Java 17 automatic migration: records #3746

Merged
merged 35 commits into from
Oct 25, 2023
Merged

Apply Java 17 automatic migration: records #3746

merged 35 commits into from
Oct 25, 2023

Conversation

Baltoli
Copy link
Contributor

@Baltoli Baltoli commented Oct 24, 2023

This PR applies automatic fixes suggested by IntelliJ to refactor Java classes into records, which reduces boilerplate code in a lot of different places.

The changes made are large, but I have split the changes up so that each commit deals only with a single class at a time, along with any downstream changes required by making that class a record. In some cases, I have applied small fix-its suggested by IntelliJ as well as the record transformation.

I'm happy to bikeshed whether any of these cases should remain a class rather than a record, and the commit history means that reverting an individual case is easy should we decide to do so.

@Baltoli Baltoli marked this pull request as ready for review October 24, 2023 14:38
Copy link
Contributor

@Scott-Guest Scott-Guest left a comment

Choose a reason for hiding this comment

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

I skimmed through all the commits, and LGTM!

I like all the small fixes from IntelliJ - we should consider using Qodana (https://www.jetbrains.com/qodana/) to enforce these on CI.

Copy link
Contributor

@radumereuta radumereuta left a comment

Choose a reason for hiding this comment

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

One comment has been lost. Not sure if it's still valid. You should check.

Copy link
Collaborator

@dwightguth dwightguth left a comment

Choose a reason for hiding this comment

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

My main comments are that it looks like the automated transformations removed final and static from the classes that were made into records. I know records are automatically final, so that part is fine, but I'm less certain that inner records are automatically static. If you can find evidence that they are, ignore all those comments, otherwise, the code probably needs to be audited to add the static keyword back in and make sure I didn't miss any places where there were inner records added.

@Baltoli
Copy link
Contributor Author

Baltoli commented Oct 24, 2023

IntelliJ explicitly prompts for the removal of static on inner records @dwightguth, and this Oracle page backs up that conclusion (ctrl-f for "implicitly static")

@Baltoli
Copy link
Contributor Author

Baltoli commented Oct 25, 2023

I have addressed and resolved all the comments left on this PR; none of them required any further changes to the code and so I'm going to merge the PR once CI passes with the merge conflicts resolved.

@rv-jenkins rv-jenkins merged commit bcef71b into develop Oct 25, 2023
8 checks passed
@rv-jenkins rv-jenkins deleted the java-records branch October 25, 2023 12:21
rv-jenkins added a commit that referenced this pull request Oct 26, 2023
This PR applies all automatic cleanups that IntelliJ is confident enough
to apply silently with no further user input; a rough summary of the
different kinds of change are:
* Removal of redundant casts (`T t = (T) v` where `v` already has type
`T`).
* Removal of unnecessary calls to `toString()`
* Insertion of `final` where possible
* Collapsing of redundant boolean conditions `if (cond) return true else
return false`
* Syntactic fixes (`;;` etc.)
* Use of `StandardCharsets.UTF_8` to simplify exception checks when
encoding strings
* Removal of redundant explicit key checks when removing values from
hashmaps

As ever, I'm happy to bikeshed these changes - I can redo the analysis
and disable some subset of the checks if anyone has objections to the
specific results we get.

~~To avoid merge conflicts, this PR is based on #3746 and should only be
merged when that PR is merged.~~

---------

Co-authored-by: rv-jenkins <[email protected]>
@Baltoli Baltoli mentioned this pull request Dec 12, 2023
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.

5 participants