From d6043e7a1948bbc0a0ca519f9fbd74322b6694ed Mon Sep 17 00:00:00 2001 From: Jaroslav Beran Date: Sat, 31 Oct 2020 11:38:23 +0100 Subject: [PATCH] Try-with-resources fix --- pom.xml | 4 ++-- src/main/java/cz/webstones/words/Service.java | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 243b72d..7c26546 100644 --- a/pom.xml +++ b/pom.xml @@ -64,8 +64,8 @@ maven-compiler-plugin 2.3.2 - 1.7 - 1.7 + 1.8 + 1.8 diff --git a/src/main/java/cz/webstones/words/Service.java b/src/main/java/cz/webstones/words/Service.java index 92b7ced..84796b0 100644 --- a/src/main/java/cz/webstones/words/Service.java +++ b/src/main/java/cz/webstones/words/Service.java @@ -139,7 +139,6 @@ public static Setup getSetup(boolean createLocalCopy, String dictPath) { } private static Setup loadSetup(File f, String dictPath, Setup setup) throws IOException { - InputStream is; Properties props = new Properties(); if (setup == null) { @@ -147,15 +146,16 @@ private static Setup loadSetup(File f, String dictPath, Setup setup) throws IOEx } if (f != null) { - is = new FileInputStream(f); + try (InputStream is = new FileInputStream(f)) { + props.load(is); + } } else { Class cls = Setup.class; ClassLoader cLoader = cls.getClassLoader(); - is = cLoader.getResourceAsStream("setup.properties"); + try (InputStream is = cLoader.getResourceAsStream("setup.properties")) { + props.load(is); + } } - - props.load(is); - is.close(); setup.setDataDir(dictPath);