Skip to content

Commit

Permalink
Fixed NPE in Mass Enroll Filters
Browse files Browse the repository at this point in the history
Refactored the filtering logic to improve readability and consistency by using `Objects.equals` for comparison and added a null check with `Objects::nonNull`.
  • Loading branch information
IllianiCBT committed Aug 2, 2024
1 parent 76e9cea commit 1b488c6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion MekHQ/src/mekhq/gui/adapter/PersonnelTableMouseAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3007,8 +3007,13 @@ private void buildEducationMenusMassEnroll(Campaign campaign, List<Person> perso
// find the first faction that accepts applications from all persons in personnel
Optional<String> suitableFaction = personnel.stream()
.map(person -> academy.getFilteredFaction(campaign, person, campaign.getCurrentSystem().getFactions(campaign.getLocalDate())))
.filter(faction -> personnel.stream().allMatch(person -> faction.equals(academy.getFilteredFaction(campaign, person, campaign.getCurrentSystem().getFactions(campaign.getLocalDate())))))
.filter(faction -> personnel.stream().allMatch(person ->
Objects.equals(
faction,
academy.getFilteredFaction(campaign, person, campaign.getCurrentSystem().getFactions(campaign.getLocalDate()))
)))
.distinct()
.filter(Objects::nonNull)
.findFirst();

if (suitableFaction.isPresent()) {
Expand Down

0 comments on commit 1b488c6

Please sign in to comment.