From 580dec28e68bcc787c0dbd90b20ef5934a72a125 Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Sun, 24 Nov 2024 15:57:41 -0600 Subject: [PATCH] Fix Typo and Added `null` check in `RetirementDefectionTracker` Corrected the typo in the resource key "recentPromotion" and added a `null` check for the last promotion date before calculating the months difference. This ensures the application does not encounter a silent null pointer exception. --- .../RetirementDefectionTracker.properties | 2 +- .../RetirementDefectionTracker.java | 33 ++++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/MekHQ/resources/mekhq/resources/RetirementDefectionTracker.properties b/MekHQ/resources/mekhq/resources/RetirementDefectionTracker.properties index 432dce2533..beba1a897f 100644 --- a/MekHQ/resources/mekhq/resources/RetirementDefectionTracker.properties +++ b/MekHQ/resources/mekhq/resources/RetirementDefectionTracker.properties @@ -25,4 +25,4 @@ founder.text=Founder shares.text=Shares administrativeStrain.text=Admin Strain managementSkill.text=Management Skill -recentpromotion.text=Recently Promoted +recentPromotion.text=Recently Promoted diff --git a/MekHQ/src/mekhq/campaign/personnel/turnoverAndRetention/RetirementDefectionTracker.java b/MekHQ/src/mekhq/campaign/personnel/turnoverAndRetention/RetirementDefectionTracker.java index 7b6079dccb..8723079ffa 100644 --- a/MekHQ/src/mekhq/campaign/personnel/turnoverAndRetention/RetirementDefectionTracker.java +++ b/MekHQ/src/mekhq/campaign/personnel/turnoverAndRetention/RetirementDefectionTracker.java @@ -21,19 +21,6 @@ */ package mekhq.campaign.personnel.turnoverAndRetention; -import static mekhq.campaign.personnel.Person.getLoyaltyName; -import static mekhq.campaign.personnel.turnoverAndRetention.RetirementDefectionTracker.Payout.isBreakingContract; - -import java.io.PrintWriter; -import java.time.LocalDate; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; - -import org.apache.commons.lang3.StringUtils; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - import megamek.codeUtilities.MathUtility; import megamek.common.Compute; import megamek.common.TargetRoll; @@ -55,6 +42,18 @@ import mekhq.campaign.universe.Faction; import mekhq.campaign.universe.FactionHints; import mekhq.utilities.MHQXMLUtility; +import org.apache.commons.lang3.StringUtils; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import java.io.PrintWriter; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; +import java.util.*; +import java.util.stream.Collectors; + +import static mekhq.campaign.personnel.Person.getLoyaltyName; +import static mekhq.campaign.personnel.turnoverAndRetention.RetirementDefectionTracker.Payout.isBreakingContract; /** * @author Neoancient @@ -177,10 +176,12 @@ public Map getTargetNumbers(final @Nullable Mission mission, f LocalDate today = campaign.getLocalDate(); LocalDate lastPromotionDate = person.getLastRankChangeDate(); - long monthsBetween = ChronoUnit.MONTHS.between(lastPromotionDate, today); + if (lastPromotionDate != null) { + long monthsBetween = ChronoUnit.MONTHS.between(lastPromotionDate, today); - if (monthsBetween <= 6) { - targetNumber.addModifier(- 1, resources.getString("recentpromotion.text")); + if (monthsBetween <= 6) { + targetNumber.addModifier(-1, resources.getString("recentPromotion.text")); + } } }