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

Disregard methods beginning with write when checking for mutability of a class #1673

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

baloghadamsoftware
Copy link
Contributor

Methods beginning with write are almost always output methods (e.g. to streams) and no setters. Disregard them when deciding about mutability of a class.

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

… of a class

Methods beginning with `write` are almost always output methods (e.g. to streams) and no setters. Disregard them when deciding about mutability of a class.

Partial fix for issue [spotbugs#1601](spotbugs#1601)
@ThrawnCA
Copy link
Contributor

ThrawnCA commented Sep 2, 2021

IMO writing to a stream qualifies as changing its state. Especially with classes like ByteArrayOutputStream.

@baloghadamsoftware
Copy link
Contributor Author

baloghadamsoftware commented Sep 7, 2021

IMO writing to a stream qualifies as changing its state. Especially with classes like ByteArrayOutputStream.

You are right. However, if a non-stream class contains a method beginning with write it usually does not change the class but writes its contents into a stream.

@rovarga
Copy link
Contributor

rovarga commented Sep 14, 2021

I think the signal-to-noise ratio for write*(...) is way too high. In its current form it trips on anything java.io.Externalizable, as well as anything using writeReplace() to implement Serializable Proxy pattern -- suppressing that is quite a bit of work, too, see #1704 .

@github-actions github-actions bot added the Stale label Mar 5, 2024
@github-actions github-actions bot closed this Apr 5, 2024
@hazendaz hazendaz reopened this Apr 12, 2024
@github-actions github-actions bot removed the Stale label Apr 14, 2024
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

4 participants