From 98964638bac4377a9a403c1aadefb12dc356545f Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Sun, 10 Jun 2018 23:43:41 +1200 Subject: [PATCH] #1412 - Fix Resource leaks for properties & yaml files etc - MigrationXmlReader --- .../migrationreader/MigrationXmlReader.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/ebeaninternal/dbmigration/migrationreader/MigrationXmlReader.java b/src/main/java/io/ebeaninternal/dbmigration/migrationreader/MigrationXmlReader.java index a5b534298..e93260ba9 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/migrationreader/MigrationXmlReader.java +++ b/src/main/java/io/ebeaninternal/dbmigration/migrationreader/MigrationXmlReader.java @@ -24,12 +24,14 @@ public class MigrationXmlReader { */ public static Migration read(String resourcePath) { - InputStream is = MigrationXmlReader.class.getResourceAsStream(resourcePath); - if (is == null) { - throw new IllegalArgumentException("No resource found for path [" + resourcePath + "]"); + try (InputStream is = MigrationXmlReader.class.getResourceAsStream(resourcePath)) { + if (is == null) { + throw new IllegalArgumentException("No resource found for path [" + resourcePath + "]"); + } + return read(is); + } catch (IOException e) { + throw new IllegalArgumentException("Failed to auto close resource " + resourcePath, e); } - - return read(is); } /**