Commit d4f327ba authored by Jan Lamecki's avatar Jan Lamecki Committed by Commit Bot

Make org.chromium.chromecast.base.Unit thread-safe.

It had race condition on unsynchronized access to static field. Fixed it
by using clinit (static initializer). Other typical pattern for
singletons would be "enum MyType {INSTANCE;}".

Bug: None.
Change-Id: I421e0b9f56ef1184194be2a4e083da7e06ab114c
Reviewed-on: https://chromium-review.googlesource.com/c/1333470Reviewed-by: default avatarSimeon Anfinrud <sanfin@chromium.org>
Commit-Queue: Jan Lamecki <jachor@google.com>
Cr-Commit-Position: refs/heads/master@{#607973}
parent 11944030
......@@ -14,10 +14,9 @@ package org.chromium.chromecast.base;
* instantiable).
*/
public final class Unit {
private static Unit sInstance;
private static final Unit sInstance = new Unit();
private Unit() {}
public static Unit unit() {
if (sInstance == null) sInstance = new Unit();
return sInstance;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment