From e62240f523e184d08d0f78410eb02c70bcd76088 Mon Sep 17 00:00:00 2001 From: tastybento Date: Thu, 16 Jan 2020 17:00:23 -0800 Subject: [PATCH] Puts the GSON serialization on main thread. (#1141) https://github.com/BentoBoxWorld/BentoBox/issues/1128 --- .../bentobox/bentobox/database/sql/SQLDatabaseHandler.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/bentobox/database/sql/SQLDatabaseHandler.java b/src/main/java/world/bentobox/bentobox/database/sql/SQLDatabaseHandler.java index 20422d760..faece8e30 100644 --- a/src/main/java/world/bentobox/bentobox/database/sql/SQLDatabaseHandler.java +++ b/src/main/java/world/bentobox/bentobox/database/sql/SQLDatabaseHandler.java @@ -154,8 +154,10 @@ public class SQLDatabaseHandler extends AbstractJSONDatabaseHandler { plugin.logError("This class is not a DataObject: " + instance.getClass().getName()); return; } + // This has to be on the main thread to avoid concurrent modification errors + String toStore = getGson().toJson(instance); // Async - processQueue.add(() -> store(instance.getClass().getName(), getGson().toJson(instance), sqlConfig.getSaveObjectSQL())); + processQueue.add(() -> store(instance.getClass().getName(), toStore, sqlConfig.getSaveObjectSQL())); } private void store(String name, String toStore, String sb) {