From 69a4ec80cd66a12259202210d69796d4aa4a69c8 Mon Sep 17 00:00:00 2001 From: Felix Bergmann Date: Tue, 7 Apr 2020 10:02:22 +0200 Subject: [PATCH] Fix resource leak on exception When an exception is hit in the try statement, the readers will never get closed and leak resources --- .../java/com/gmail/nossr50/config/WorldBlacklist.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/config/WorldBlacklist.java b/src/main/java/com/gmail/nossr50/config/WorldBlacklist.java index a37b89b3e..76181377f 100644 --- a/src/main/java/com/gmail/nossr50/config/WorldBlacklist.java +++ b/src/main/java/com/gmail/nossr50/config/WorldBlacklist.java @@ -54,15 +54,15 @@ public class WorldBlacklist { if(!blacklist.contains(currentLine)) blacklist.add(currentLine); } - - //Close readers - bufferedReader.close(); - fileReader.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); + } finally { + //Close readers + if(bufferedReader != null) bufferedReader.close(); + if(fileReader != null) fileReader.close(); } plugin.getLogger().info(blacklist.size()+" entries in mcMMO World Blacklist");