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

Disable intellij's ClassCanBeRecord inspection #2225

Merged
merged 2 commits into from
Apr 25, 2022

Conversation

fawind
Copy link
Contributor

@fawind fawind commented Apr 25, 2022

Before this PR

When using JDK 17+, Intellij's ClassCanBeRecord inspection gets suggested for all classes with only final fields that get set through the constructor. However in many cases, this is not desired as this weakens the visibility of the fields by adding public getters. I would argue that for all classes that use dependency injection, this is not desired.

Example class which gets flagged:

class MyResource {
  private final Store store;
  private final OtherService otherService;

  MyResource(Store store, OtherService otherService) {
    this.store = store;
    this.otherService = otherService
  }
}

Given that this gets flagged in Intellij as a warning with the default action to automatically convert the class, I think its best to disable this inspection.

After this PR

==COMMIT_MSG==
Disable intellij's ClassCanBeRecord inspection
==COMMIT_MSG==

Possible downsides?

In some cases it might be desirable (e.g. data classes). But maybe we should handle this using an explicit error-prone check?

@changelog-app
Copy link

changelog-app bot commented Apr 25, 2022

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Disable intellij's ClassCanBeRecord inspection

Check the box to generate changelog(s)

  • Generate changelog entry

@fawind fawind requested review from carterkozak and CRogers April 25, 2022 16:21
@bulldozer-bot bulldozer-bot bot merged commit 12ecb85 into develop Apr 25, 2022
@bulldozer-bot bulldozer-bot bot deleted the fw/class-can-be-record branch April 25, 2022 16:26
@svc-autorelease
Copy link
Collaborator

Released 4.114.0

This was referenced Apr 25, 2022
bulldozer-bot bot pushed a commit to palantir/witchcraft-api that referenced this pull request Apr 25, 2022
###### _excavator_ is a bot for automating changes across repositories.

Changes produced by the roomba/latest-baseline-oss check.

# Release Notes
## 4.113.0
| Type | Description | Link |
| ---- | ----------- | ---- |
| Improvement | Streamline Throwable safety handling | palantir/gradle-baseline#2224 |


## 4.114.0
| Type | Description | Link |
| ---- | ----------- | ---- |
| Improvement | Disable intellij's ClassCanBeRecord inspection | palantir/gradle-baseline#2225 |



To enable or disable this check, please contact the maintainers of Excavator.
This was referenced Apr 25, 2022
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.

4 participants