From 17fc231db684fad977a939af569c2b3b23737ebc Mon Sep 17 00:00:00 2001 From: austinio7116 Date: Sun, 15 Apr 2018 00:24:39 +0100 Subject: [PATCH] Fix to ensure invalid format files do not crash game on startup --- .../StorageReaderRecursiveFolderWithUserFolder.java | 2 +- forge-game/src/main/java/forge/game/GameFormat.java | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/forge-core/src/main/java/forge/util/storage/StorageReaderRecursiveFolderWithUserFolder.java b/forge-core/src/main/java/forge/util/storage/StorageReaderRecursiveFolderWithUserFolder.java index 667039074b3..fba09b57f74 100644 --- a/forge-core/src/main/java/forge/util/storage/StorageReaderRecursiveFolderWithUserFolder.java +++ b/forge-core/src/main/java/forge/util/storage/StorageReaderRecursiveFolderWithUserFolder.java @@ -98,7 +98,7 @@ public abstract class StorageReaderRecursiveFolderWithUserFolder extends Stor final T newDeck = this.read(file); if (null == newDeck) { final String msg = "An object stored in " + file.getPath() + " failed to load.\nPlease submit this as a bug with the mentioned file/directory attached."; - throw new RuntimeException(msg); + continue;//skip format completely - perhaps non format file } String newKey = keySelector.apply(newDeck); diff --git a/forge-game/src/main/java/forge/game/GameFormat.java b/forge-game/src/main/java/forge/game/GameFormat.java index 4acc56dc879..adea7a445a2 100644 --- a/forge-game/src/main/java/forge/game/GameFormat.java +++ b/forge-game/src/main/java/forge/game/GameFormat.java @@ -300,7 +300,11 @@ public class GameFormat implements Comparable { Boolean restrictedLegendary = false; List additionalCards = null; // default: nothing additional List rarities = null; - FileSection section = FileSection.parse(contents.get("format"), ":"); + List formatStrings = contents.get("format"); + if (formatStrings == null){ + return null; + } + FileSection section = FileSection.parse(formatStrings, ":"); String title = section.get("name"); FormatType formatType; try { @@ -315,10 +319,11 @@ public class GameFormat implements Comparable { formatsubType = FormatSubType.Custom; } Integer idx = section.getInt("order"); - Date date = parseDate(section.get("effectivedate")); - if (date == null){ - date = parseDate(DEFAULTDATE); + String dateStr = section.get("effectivedate"); + if (dateStr == null){ + dateStr = DEFAULTDATE; } + Date date = parseDate(dateStr); String strSets = section.get("sets"); if ( null != strSets ) { sets = Arrays.asList(strSets.split(", "));