ensure closing of scanner if it was opened

This commit is contained in:
Marc Zwart 2018-03-20 10:52:53 +01:00
parent 0da4e10c49
commit 7b3d6a60b6

View file

@ -957,10 +957,11 @@ public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ {
}
protected final void getSuggestedActions() {
Scanner scanner = null;
try {
File file = new File(FILE_WITH_INSTRUCTIONS);
if (file.exists()) {
Scanner scanner = new Scanner(file);
scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.startsWith("cast:")
@ -976,6 +977,10 @@ public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ {
} catch (Exception e) {
// swallow
e.printStackTrace();
} finally {
if(scanner != null) {
scanner.close();
}
}
}