Browse Source

Fix resource leak on exception

When an exception is hit in the try statement, the readers will never get closed and leak resources
Felix Bergmann 5 years ago
parent
commit
69a4ec80cd
1 changed files with 4 additions and 4 deletions
  1. 4 4
      src/main/java/com/gmail/nossr50/config/WorldBlacklist.java

+ 4 - 4
src/main/java/com/gmail/nossr50/config/WorldBlacklist.java

@@ -54,15 +54,15 @@ public class WorldBlacklist {
                 if(!blacklist.contains(currentLine))
                 if(!blacklist.contains(currentLine))
                     blacklist.add(currentLine);
                     blacklist.add(currentLine);
             }
             }
-
-            //Close readers
-            bufferedReader.close();
-            fileReader.close();
         } catch (FileNotFoundException e) {
         } catch (FileNotFoundException e) {
             e.printStackTrace();
             e.printStackTrace();
         } catch (IOException e)
         } catch (IOException e)
         {
         {
             e.printStackTrace();
             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");
         plugin.getLogger().info(blacklist.size()+" entries in mcMMO World Blacklist");