diff --git a/game-app/game-core/src/main/java/games/strategy/engine/data/PlayerList.java b/game-app/game-core/src/main/java/games/strategy/engine/data/PlayerList.java index c7c94d7f601..81dad738d88 100644 --- a/game-app/game-core/src/main/java/games/strategy/engine/data/PlayerList.java +++ b/game-app/game-core/src/main/java/games/strategy/engine/data/PlayerList.java @@ -3,6 +3,8 @@ import com.google.common.annotations.VisibleForTesting; import games.strategy.triplea.Constants; import games.strategy.triplea.util.PlayerOrderComparator; +import java.io.IOException; +import java.io.ObjectInputStream; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -14,6 +16,7 @@ import java.util.stream.Stream; import lombok.Getter; import lombok.ToString; +import org.triplea.java.RemoveOnNextMajorRelease; /** Wrapper around the set of players in a game to provide utility functions and methods. */ @ToString @@ -22,19 +25,31 @@ public class PlayerList extends GameDataComponent implements Iterable PlayerId private final Map players = new LinkedHashMap<>(); - @Getter private final GamePlayer nullPlayer; + @Getter private GamePlayer nullPlayer; public PlayerList(final GameData data) { super(data); - nullPlayer = - new GamePlayer(Constants.PLAYER_NAME_NEUTRAL, true, false, null, false, data) { - private static final long serialVersionUID = 1; - - @Override - public boolean isNull() { - return true; - } - }; + nullPlayer = createNullPlayer(data); + } + + @RemoveOnNextMajorRelease + private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { + in.defaultReadObject(); + // Old save games may not have nullPlayer set. + if (nullPlayer == null) { + nullPlayer = createNullPlayer(getData()); + } + } + + private GamePlayer createNullPlayer(GameData data) { + return new GamePlayer(Constants.PLAYER_NAME_NEUTRAL, true, false, null, false, data) { + private static final long serialVersionUID = 1; + + @Override + public boolean isNull() { + return true; + } + }; } @VisibleForTesting