Skip to content

Commit

Permalink
Fix NPE when canal validation is sent null unit list (#3907)
Browse files Browse the repository at this point in the history
  • Loading branch information
ron-murhammer committed Aug 28, 2018
1 parent 615b2e2 commit b936347
Showing 1 changed file with 5 additions and 4 deletions.
Expand Up @@ -232,7 +232,8 @@ private static String validateCanal(final Route route, final Collection<Unit> un
// Check each unit 1 by 1 to see if they can move through necessary canals on route
String result = null;
final Set<Unit> unitsThatFailCanal = new HashSet<>();
final Collection<Unit> unitsWithoutDependents = findNonDependentUnits(units, route, newDependents);
final Collection<Unit> unitsWithoutDependents =
(units == null) ? Collections.singleton(null) : findNonDependentUnits(units, route, newDependents);
for (final Unit unit : unitsWithoutDependents) {
for (final Territory t : route.getAllTerritories()) {
Optional<String> failureMessage = Optional.empty();
Expand All @@ -253,8 +254,8 @@ private static String validateCanal(final Route route, final Collection<Unit> un
}
}
}
if (result == null) {
return null;
if (result == null || units == null) {
return result;
}

// If any units failed canal check then try to land transport them
Expand Down Expand Up @@ -1279,7 +1280,7 @@ private static boolean isCanalOnRoute(final CanalAttachment canalAttachment, fin
*/
private static Optional<String> canPassThroughCanal(final CanalAttachment canalAttachment,
final Unit unit, final PlayerID player, final GameData data) {
if (Matches.unitIsOfTypes(canalAttachment.getExcludedUnits()).test(unit)) {
if (unit != null && Matches.unitIsOfTypes(canalAttachment.getExcludedUnits()).test(unit)) {
return Optional.empty();
}
for (final Territory borderTerritory : canalAttachment.getLandTerritories()) {
Expand Down

0 comments on commit b936347

Please sign in to comment.