Skip to content

Commit

Permalink
Fix scanner resource leak.
Browse files Browse the repository at this point in the history
Wraps the Scanner in try-with-resources to ensure resource cleanup after
reading the config-file from the plugin jar.
  • Loading branch information
tadhunt committed Oct 21, 2023
1 parent 15a79bd commit a8b2cf9
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.Set;

Expand Down Expand Up @@ -46,11 +47,15 @@ private static void process(Plugin plugin, String resource, ConfigurationSection
if (is == null) {
throw new IllegalStateException("Couldn't read " + res + " from jar, please re-install MobArena");
}
Scanner scanner = new Scanner(is).useDelimiter("\\A");
if (!scanner.hasNext()) {

String contents;
try (Scanner scanner = new Scanner(is)) {
scanner.useDelimiter("\\A");
contents = scanner.next();
} catch (NoSuchElementException e) {
throw new IllegalStateException("No content in " + res + " in jar, please re-install MobArena");
}
String contents = scanner.next();

YamlConfiguration yaml = new YamlConfiguration();
try {
yaml.loadFromString(contents);
Expand Down

0 comments on commit a8b2cf9

Please sign in to comment.