From 8f6dcb8ba6aaca9a78a0ac6dfa4a5b5e73af0aaf Mon Sep 17 00:00:00 2001 From: PepperBell <44146161+PepperCode1@users.noreply.github.com> Date: Thu, 22 Jul 2021 16:13:03 -0700 Subject: [PATCH] Fix resource leak - Fix ponder resources not being closed properly --- .../create/foundation/ponder/PonderRegistry.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/ponder/PonderRegistry.java b/src/main/java/com/simibubi/create/foundation/ponder/PonderRegistry.java index ffe9fc99e..ee420a6f4 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/PonderRegistry.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/PonderRegistry.java @@ -2,6 +2,7 @@ package com.simibubi.create.foundation.ponder; import java.io.BufferedInputStream; import java.io.DataInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -140,15 +141,12 @@ public class PonderRegistry { String path = "ponder/" + location.getPath() + ".nbt"; ResourceLocation location1 = new ResourceLocation(namespace, path); - if (!resourceManager.hasResource(location1)) { - Create.LOGGER.error("Ponder schematic missing: " + location1); - return new Template(); - } - try { - IResource resource = resourceManager.getResource(location1); + try (IResource resource = resourceManager.getResource(location1)) { return loadSchematic(resource.getInputStream()); + } catch (FileNotFoundException e) { + Create.LOGGER.error("Ponder schematic missing: " + location1, e); } catch (IOException e) { - Create.LOGGER.error("Failed to read ponder schematic: " + path, e); + Create.LOGGER.error("Failed to read ponder schematic: " + location1, e); } return new Template(); }