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

Exclude methods returning any object from potential setters when deciding on the mutability of a class #1674

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

baloghadamsoftware
Copy link
Contributor

@baloghadamsoftware baloghadamsoftware commented Aug 31, 2021

Methods which returned an instance of the owning class itself are probably no setters because they usually return a new instance instead of modifying the existing one. The algorithm did care for that, but it turned out that in many cases this is not enough. Some immutable classes contain methods with a setter-like name which return an instance of a class which is different from their owning class. This patch changes the behavior of the alrogithm to skip these methods as well.

Partial fix for issue [#1601](https://github.com/spotbugs/spotbugs/issues/1601\)


Make sure these boxes are checked before submitting your PR -- thank you!

  • Added an entry into CHANGELOG.md if you have changed SpotBugs code

Ádám Balogh added 2 commits August 31, 2021 17:48
…ding on the mutability of a class

Methods which returned an instance of the owning class itself are probably no setters because they usually return a new instance instead of modifying the existing one. The algorithm did care for that, but it turned out that in many cases this is not enough. Some immutable classes contain methods with a setter-like name which return an instance of a class which is different from their owning class. This patch changes the behavior of the alrogithm to skip these methods as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants