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

Version 4.8.4 false positive SING_SINGLETON_GETTER_NOT_SYNCHRONIZED #2967

Closed
garydgregory opened this issue Apr 23, 2024 · 6 comments · Fixed by #2951
Closed

Version 4.8.4 false positive SING_SINGLETON_GETTER_NOT_SYNCHRONIZED #2967

garydgregory opened this issue Apr 23, 2024 · 6 comments · Fixed by #2951

Comments

@garydgregory
Copy link

garydgregory commented Apr 23, 2024

Spotbugs thinks there is a getter mehod to synchronize when there is none and raises a SING_SINGLETON_GETTER_NOT_SYNCHRONIZED.
To reproduce:

git clone https://gitbox.apache.org/repos/asf/commons-text.git
cd commons-text
git checkout 70436ca75ed10dd72269d4218a0cb844276d0ba9
mvn clean verify spotbugs:check -Dcommons.spotbugs.impl.version=4.8.4 -DskipTests

Will cause 10 errors when 4.8.3 raises none, including:

[ERROR] Medium: Class (org.apache.commons.text.similarity.IntersectionSimilarity$BagCount) using singleton design pattern has non-private constructor. [org.apache.commons.text.similarity.IntersectionSimilarity$BagCount] At IntersectionSimilarity.java:[line 43] SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR

On https://spotbugs.readthedocs.io/en/latest/bugDescriptions.html, SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR says:

SING: Instance-getter method of class using singleton design pattern is not synchronized. (SING_SINGLETON_GETTER_NOT_SYNCHRONIZED)[](https://spotbugs.readthedocs.io/en/latest/bugDescriptions.html#sing-instance-getter-method-of-class-using-singleton-design-pattern-is-not-synchronized-sing-singleton-getter-not-synchronized)

Instance-getter method of class using singleton design pattern is not synchronized. When this method is invoked by two or more threads simultaneously, multiple instantiation of a singleton class becomes possible.

[SEI CERT MSC07-J](https://wiki.sei.cmu.edu/confluence/display/java/MSC07-J.+Prevent+multiple+instantiations+of+singleton+objects) rule

Which sure seems like silly since there is such method.

Please advise...
TY!

@JuditKnoll
Copy link
Collaborator

JuditKnoll commented Apr 24, 2024

I taken a look at the results.
Most of them (including the mentioned one) seems to be FPs, which will be solved by #2951 once it's merged (or is already solved by #2943 on master). I'm sorry for the inconvience.
I only found two true positives:

[ERROR] Medium: Class (org.apache.commons.text.similarity.LevenshteinDetailedDistance) using singleton design pattern has non-private constructor. [org.apache.commons.text.similarity.LevenshteinDetailedDistance] At LevenshteinDetailedDistance.java:[lines 457-458] SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR

[ERROR] Medium: Class (org.apache.commons.text.similarity.LevenshteinDistance) using singleton design pattern has non-private constructor. [org.apache.commons.text.similarity.LevenshteinDistance] At LevenshteinDistance.java:[lines 332-333] SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR

@JuditKnoll JuditKnoll linked a pull request Apr 24, 2024 that will close this issue
@garydgregory
Copy link
Author

@JuditKnoll
TY for your analysis and feedback.
I'll wait to release the Apache Commons Parent POM for this fix. Would you please set expectations as to a release date?

@JuditKnoll
Copy link
Collaborator

IMO SpotBugs 4.8.5 will be released in a few weeks time, if nothing really messed up comes up which should be addressed in the next release.

@garydgregory
Copy link
Author

Great, ty.

asfgit pushed a commit to apache/commons-parent that referenced this issue Apr 24, 2024
@hazendaz
Copy link
Member

hazendaz commented Apr 25, 2024 via email

@garydgregory
Copy link
Author

I like RERO ! 👍 😄

sosy-bot pushed a commit to sosy-lab/cpachecker that referenced this issue Apr 30, 2024
This reverts commit 15a05c1.

SpotBugs 4.8.4 has at least one problem
(spotbugs/spotbugs#2967)
so we wait for the next version.
Somehow I didn't notice this at first when trying it out locally.

git-svn-id: https://svn.sosy-lab.org/software/cpachecker/trunk@46371 4712c6d2-40bb-43ae-aa4b-fec3f1bdfe4c
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 a pull request may close this issue.

3 participants