-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Lazy initialization of static fields should be synchronized #1198
Lazy initialization of static fields should be synchronized #1198
Conversation
Hi @kirill-vlasov , can you open a Jira for this issue. Thanks a lot |
@vladmihalcea this can be merged without needing the CLA. Thanks! |
@kirill-vlasov The |
@@ -150,7 +150,7 @@ else if ( member instanceof Field ) { | |||
|
|||
private static Method memberMethod; | |||
|
|||
private static Member toMember(XProperty xProperty) { | |||
private static synchronized Member toMember(XProperty xProperty) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, something is fishy here! Yet synchronizing is not the best solution, as it would introduce a contention point while it's not necessary.
The memberMethod
should be made final
and initialized statically.
Also, would be nice to have fields at the beginning of the class.
@richardfontana thanks! It's great to see you around, even more helping so directly. |
I created HHH-10715 for analyzing static field usage. |
I was just checking for similar patterns, and I'm glad to say that most issues had already been resolved. I just fixed the remaining cases. |
This pull request is focused on resolving occurrences of Sonar rule squid:S2444 - Lazy initialization of static fields should be synchronized
You can find more information about the issue here:
https://dev.eclipse.org/sonar/coding_rules#q=squid:S2444
Please let me know if you have any questions.
Kirill Vlasov