further proper resource closing in ServerMessagesUtil
*/
package mage.server.util;
+import mage.utils.StreamUtils;
import org.apache.log4j.Logger;
import java.io.File;
@@ -147,14 +148,23 @@ instance;
log.warn("Couldn't find server.msg");
return null;
}
- Scanner scanner = new Scanner(is);
+
+ Scanner scanner = null;
List<String> newMessages = new ArrayList<>();
+ try {
+ scanner = new Scanner(is);
while (scanner.hasNextLine()) {
String message = scanner.nextLine();
if (!message.trim().isEmpty()) {
newMessages.add(message.trim());
}
}
+ } catch(Exception e) {
+ log.error(e,e);
+ } finally {
+ StreamUtils.closeQuietly(scanner);
+ StreamUtils.closeQuietly(is);
+ }
return newMessages;
}
