From 2879834a7e8acdbfb110dad310f1380366cb41b9 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 5 Apr 2014 03:47:33 +1300 Subject: [PATCH] Close the stream safely --- src/me/libraryaddict/disguise/LibsDisguises.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index cc118b3c..53c2ba11 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -41,17 +41,25 @@ public class LibsDisguises extends JavaPlugin { saveDefaultConfig(); FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "config.yml")); boolean needToSaveConfig = false; + InputStream stream = null; try { - InputStream stream = getClassLoader().getResource("config.yml").openStream(); + stream = getClassLoader().getResource("config.yml").openStream(); for (String option : YamlConfiguration.loadConfiguration(stream).getKeys(false)) { if (!config.contains(option)) { config.set(option, getConfig().get(option)); needToSaveConfig = true; } } - stream.close(); } catch (IOException e) { e.printStackTrace(); + } finally { + try { + if (stream != null) { + stream.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } } if (needToSaveConfig) { try {