diff --git a/game-core/src/main/java/games/strategy/engine/data/changefactory/AddUnits.java b/game-core/src/main/java/games/strategy/engine/data/changefactory/AddUnits.java index 8fc41067769..24700ef8fe9 100644 --- a/game-core/src/main/java/games/strategy/engine/data/changefactory/AddUnits.java +++ b/game-core/src/main/java/games/strategy/engine/data/changefactory/AddUnits.java @@ -42,7 +42,16 @@ public class AddUnits extends Change { } private Map buildUnitOwnerMap(final Collection units) { - return units.stream().collect(Collectors.toMap(Unit::getId, unit -> unit.getOwner().getName())); + return units.stream() + .collect( + Collectors.toMap( + Unit::getId, + unit -> { + if (unit.getOwner() == null || unit.getOwner().getName() == null) { + return null; + } + return unit.getOwner().getName(); + })); } @Override @@ -67,8 +76,10 @@ private Collection buildUnitsWithOwner(final GameData data) { if (unit == null) { unit = uuidToUnits.get(entry.getKey()); } - final GamePlayer player = data.getPlayerList().getPlayerId(entry.getValue()); - unit.setOwner(player); + if (entry.getValue() != null) { + final GamePlayer player = data.getPlayerList().getPlayerId(entry.getValue()); + unit.setOwner(player); + } return unit; }) .collect(Collectors.toList());