Synchronize cache access

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-03-26 13:05:21 +01:00
parent 85559abb28
commit ac4d78acf1

View File

@ -111,20 +111,20 @@ final class TagHandlerImpl implements TagHandler {
}
entries[index] = new Entry<>(tag, nbt);
}
synchronized (this) {
this.cache = null;
this.entries = entries;
}
}
@Override
public @NotNull NBTCompound asCompound() {
return updatedCache().compound;
}
private Cache updatedCache() {
private synchronized Cache updatedCache() {
Cache cache = this.cache;
if (cache == null) {
synchronized (this) {
if ((cache = this.cache) != null) return cache;
Entry<?>[] entries = this.entries;
if (entries.length > 0) {
entries = entries.clone();
@ -146,7 +146,6 @@ final class TagHandlerImpl implements TagHandler {
}
this.cache = cache;
}
}
return cache;
}