Skip to content

Commit

Permalink
Fix 2.6 NoSuchElementException in AA code. (#11734)
Browse files Browse the repository at this point in the history
This would happen if a unit has special chars in its aaType, causing it to be evaluated as a regex instead of an exact match.
This specifically broke the code pattern (e.g. in FiringGroupSplitterAa):

    final List<String> typeAas = UnitAttachment.getAllOfTypeAas(aaUnits);
    for (final String typeAa : typeAas) {
      final Collection<Unit> firingUnits =
          CollectionUtils.getMatches(aaUnits, Matches.unitIsAaOfTypeAa(typeAa));

Causing an empty `firingUnits` due to typeAa being evaluated as a regex.
I checked all the callsites and verified none of them actually require the regex behavior.

Fixes: #11458
  • Loading branch information
asvitkine committed Jul 5, 2023
1 parent b47bf38 commit 6711573
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ private static Predicate<UnitType> unitTypeCanBeHitByAaFire(
}

public static Predicate<Unit> unitIsAaOfTypeAa(final String typeAa) {
return u -> u.getUnitAttachment().getTypeAa().matches(typeAa);
return u -> u.getUnitAttachment().getTypeAa().equals(typeAa);
}

public static Predicate<Unit> unitAaShotDamageableInsteadOfKillingInstantly() {
Expand Down

0 comments on commit 6711573

Please sign in to comment.