From 6b7e9c1132d8b26446577c8a14f9cf50175638db Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sun, 6 Jan 2019 12:32:06 +0200 Subject: [PATCH] Closed some ConfigReaders appropriately --- .../system/database/databases/sql/tables/SettingsTable.java | 4 +++- .../djrapitops/plan/system/settings/config/ConfigReader.java | 2 +- .../plan/system/settings/network/NetworkSettingManager.java | 4 ++-- .../plan/system/settings/network/ServerSettingsManager.java | 4 ++-- .../plan/system/settings/changes/ConfigChangeTest.java | 4 ---- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/SettingsTable.java b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/SettingsTable.java index a4a5bf017..4485888c4 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/SettingsTable.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/SettingsTable.java @@ -152,7 +152,9 @@ public class SettingsTable extends Table { @Override public Config processResults(ResultSet set) throws SQLException { if (set.next()) { - return new ConfigReader(new Scanner(set.getString(Col.CONFIG_CONTENT.get()))).read(); + try (ConfigReader reader = new ConfigReader(new Scanner(set.getString(Col.CONFIG_CONTENT.get())))) { + return reader.read(); + } } else { return null; } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/settings/config/ConfigReader.java b/Plan/common/src/main/java/com/djrapitops/plan/system/settings/config/ConfigReader.java index 9dab22e0a..9b54a4cec 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/settings/config/ConfigReader.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/settings/config/ConfigReader.java @@ -243,7 +243,7 @@ public class ConfigReader implements Closeable { } @Override - public void close() throws IOException { + public void close() { scanner.close(); closed = true; } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/settings/network/NetworkSettingManager.java b/Plan/common/src/main/java/com/djrapitops/plan/system/settings/network/NetworkSettingManager.java index 9fa00a6b5..6c2114cd0 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/settings/network/NetworkSettingManager.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/settings/network/NetworkSettingManager.java @@ -185,8 +185,8 @@ public class NetworkSettingManager implements SubSystem { Database database = dbSystem.getDatabase(); - try { - Config config = new ConfigReader(file.toPath()).read(); + try (ConfigReader reader = new ConfigReader(file.toPath())) { + Config config = reader.read(); database.save().saveConfig(serverUUID, config); } catch (IOException e) { throw new UncheckedIOException(e); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/settings/network/ServerSettingsManager.java b/Plan/common/src/main/java/com/djrapitops/plan/system/settings/network/ServerSettingsManager.java index 6c22fbc30..8586ee0c0 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/settings/network/ServerSettingsManager.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/settings/network/ServerSettingsManager.java @@ -105,8 +105,8 @@ public class ServerSettingsManager implements SubSystem { Database database = dbSystem.getDatabase(); - try { - Config config = new ConfigReader(file.toPath()).read(); + try (ConfigReader reader = new ConfigReader(file.toPath())) { + Config config = reader.read(); database.save().saveConfig(serverInfo.getServerUUID(), config); } catch (IOException e) { throw new UncheckedIOException(e); diff --git a/Plan/common/src/test/java/com/djrapitops/plan/system/settings/changes/ConfigChangeTest.java b/Plan/common/src/test/java/com/djrapitops/plan/system/settings/changes/ConfigChangeTest.java index a52861cb5..dc79480c3 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/system/settings/changes/ConfigChangeTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/system/settings/changes/ConfigChangeTest.java @@ -26,8 +26,6 @@ import org.junit.runner.RunWith; import org.junitpioneer.jupiter.TempDirectory; import org.mockito.junit.jupiter.MockitoExtension; -import java.io.IOException; -import java.io.UncheckedIOException; import java.nio.file.Path; import java.util.Scanner; @@ -50,8 +48,6 @@ class ConfigChangeTest { private Config prepareConfig(String withValue) { try (ConfigReader reader = new ConfigReader(new Scanner(withValue))) { return new Config(temporaryFolder.resolve("config.yml").toFile(), reader.read()); - } catch (IOException e) { - throw new UncheckedIOException(e); } }