Fix race conditions in LabelTypes map creation
Change-Id: I9e6d51f73bd664e82d9f54d127bbdd5bc46ab382
This commit is contained in:
parent
a72c23cee3
commit
9cad868a80
@ -50,10 +50,15 @@ public class LabelTypes {
|
|||||||
|
|
||||||
private Map<String, LabelType> byLabel() {
|
private Map<String, LabelType> byLabel() {
|
||||||
if (byLabel == null) {
|
if (byLabel == null) {
|
||||||
byLabel = new HashMap<String, LabelType>();
|
synchronized (this) {
|
||||||
if (labelTypes != null) {
|
if (byLabel == null) {
|
||||||
for (LabelType t : labelTypes) {
|
Map<String, LabelType> l = new HashMap<String, LabelType>();
|
||||||
byLabel.put(t.getName().toLowerCase(), t);
|
if (labelTypes != null) {
|
||||||
|
for (LabelType t : labelTypes) {
|
||||||
|
l.put(t.getName().toLowerCase(), t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
byLabel = l;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,11 +93,16 @@ public class LabelTypes {
|
|||||||
|
|
||||||
private Map<String, Integer> positions() {
|
private Map<String, Integer> positions() {
|
||||||
if (positions == null) {
|
if (positions == null) {
|
||||||
positions = new HashMap<String, Integer>();
|
synchronized (this) {
|
||||||
if (labelTypes != null) {
|
if (positions == null) {
|
||||||
int i = 0;
|
Map<String, Integer> p = new HashMap<String, Integer>();
|
||||||
for (LabelType t : labelTypes) {
|
if (labelTypes != null) {
|
||||||
positions.put(t.getName(), i++);
|
int i = 0;
|
||||||
|
for (LabelType t : labelTypes) {
|
||||||
|
p.put(t.getName(), i++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
positions = p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user