synchronizedList must be in a synchronized block when iterating

This commit is contained in:
PrototypeTrousers
2022-11-08 18:00:30 -03:00
parent 87fcc6c267
commit 1f12fc5e91
+8 -5
View File
@@ -67,11 +67,12 @@ public class ItemRepo {
public IAEItemStack getReferenceItem(int idx) {
idx += this.src.getCurrentScroll() * this.rowSize;
if (idx >= this.view.size()) {
return null;
synchronized (this.view) {
if (idx >= this.view.size()) {
return null;
}
return this.view.get(idx);
}
return this.view.get(idx);
}
void setSearch(final String search) {
@@ -209,7 +210,9 @@ public class ItemRepo {
return view;
}).thenAcceptAsync(view -> {
this.view.clear();
synchronized (this.view) {
this.view.clear();
}
this.view.addAll(view);
}).thenRunAsync(() -> {
this.searchTask = null; // Prevent redundant cancellation