-
Notifications
You must be signed in to change notification settings - Fork 578
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
FP SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR for record #2981
Comments
Thanks for reporting this issue. I will take a closer look at it next week. |
A record must have a non private constructor, so it can't be a singleton here. |
@gtoison a private record can have only private constructors. I don't know how relevant that is for "real" code. Could be used as a singleton holder for the enclosing class. |
Ah you're right, I got confused with the canonical record constructor |
This month was quite busy for me, and I could not look into this issue. If anyone is interested, feel free to take it. If no one takes it up, I'll look into it at the earliest 2 weeks from now. |
After #2934 was fixed, most problems with singletons seem to be solved. There still is one left. I don't know if there's an easy way to fix this - if not, I'll add an exclusion rule in my code.
I have the following record class where SpotBugs still reports a false positive SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR:
The problem I think is that it's not easy to tell if something should be a singleton or not. And you could implement a singleton as a record, but it is rather usual IMHO. I this example, the static final member is not intended as a singleton instance, but is used as a guard value.
The text was updated successfully, but these errors were encountered: