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

Fix issue: getters and setters should be synchronized in pairs #1725

Closed
wants to merge 1 commit into from
Closed

Conversation

igor-suhorukov
Copy link
Contributor

When one part of a getter/setter pair is synchronized the other part should be too. Failure to synchronize both sides of a pair may result in inconsistent behaviour at runtime as callers access an inconsistent method state.

@jhoeller
Copy link
Contributor

jhoeller commented Mar 8, 2018

Again well spotted! Thanks for pointing the finger at all of those... You're keeping me quite busy there :-)

I've addressed this one differently in avoiding full synchronization as far as possible: The underlying fields are volatile now, and the getters use a double-check lock, only entering full synchronization when no existing instance has been found. All we want to prevent there is entering the lazy initialization algorithm concurrently; once initialized, we're happy to go with whatever has been set, so a volatile field is sufficient there. We're using such a pattern in quite a few other places since it provides a reasonable tradeoff for all kinds of lazy default initialization.

@jhoeller jhoeller closed this Mar 8, 2018
@igor-suhorukov
Copy link
Contributor Author

@jhoeller thanks, I understand

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