Thread safety is not assured without legacyPath being volatile.
Change-Id: I7e69777cb4af6b3bc359a0a2b218ecdba433f369
Signed-off-by: Robert Varga <rovarga@cisco.com>
* Cached legacy path, filled-in when {@link #getPath()} or {@link #getPathTowardsRoot()}
* is invoked.
*/
- private ImmutableList<QName> legacyPath;
+ private volatile ImmutableList<QName> legacyPath;
private ImmutableList<QName> getLegacyPath() {
- if (legacyPath == null) {
- legacyPath = ImmutableList.copyOf(getPathTowardsRoot()).reverse();
+ ImmutableList<QName> ret = legacyPath;
+ if (ret == null) {
+ synchronized (this) {
+ ret = legacyPath;
+ if (ret == null) {
+ ret = ImmutableList.copyOf(getPathTowardsRoot()).reverse();
+ legacyPath = ret;
+ }
+ }
}
- return legacyPath;
+ return ret;
}
/**