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() {
|
||||
if (byLabel == null) {
|
||||
byLabel = new HashMap<String, LabelType>();
|
||||
if (labelTypes != null) {
|
||||
for (LabelType t : labelTypes) {
|
||||
byLabel.put(t.getName().toLowerCase(), t);
|
||||
synchronized (this) {
|
||||
if (byLabel == null) {
|
||||
Map<String, LabelType> l = new HashMap<String, LabelType>();
|
||||
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() {
|
||||
if (positions == null) {
|
||||
positions = new HashMap<String, Integer>();
|
||||
if (labelTypes != null) {
|
||||
int i = 0;
|
||||
for (LabelType t : labelTypes) {
|
||||
positions.put(t.getName(), i++);
|
||||
synchronized (this) {
|
||||
if (positions == null) {
|
||||
Map<String, Integer> p = new HashMap<String, Integer>();
|
||||
if (labelTypes != null) {
|
||||
int i = 0;
|
||||
for (LabelType t : labelTypes) {
|
||||
p.put(t.getName(), i++);
|
||||
}
|
||||
}
|
||||
positions = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user