From 0069d2fabc9fa5e56319bbcc7bf2cc92768a5ae3 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Sun, 10 Jun 2018 23:46:55 +1200 Subject: [PATCH] #1412 - Fix Resource leaks for properties & yaml files etc - ExtraDdlXmlReader --- .../extraddl/model/ExtraDdlXmlReader.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/ebeaninternal/extraddl/model/ExtraDdlXmlReader.java b/src/main/java/io/ebeaninternal/extraddl/model/ExtraDdlXmlReader.java index a478a1ac7..1cb735073 100644 --- a/src/main/java/io/ebeaninternal/extraddl/model/ExtraDdlXmlReader.java +++ b/src/main/java/io/ebeaninternal/extraddl/model/ExtraDdlXmlReader.java @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; +import java.io.IOException; import java.io.InputStream; /** @@ -87,12 +88,15 @@ public class ExtraDdlXmlReader { */ public static ExtraDdl read(String resourcePath) { - InputStream is = ExtraDdlXmlReader.class.getResourceAsStream(resourcePath); - if (is == null) { - // we expect this and check for null - return null; + try (InputStream is = ExtraDdlXmlReader.class.getResourceAsStream(resourcePath)) { + if (is == null) { + // we expect this and check for null + return null; + } + return read(is); + } catch (IOException e) { + throw new IllegalStateException("Error on auto close of " + resourcePath, e); } - return read(is); } /**