From 7db4403f6f9c1408fff5b17d526d52df52860359 Mon Sep 17 00:00:00 2001 From: asvitkine Date: Tue, 4 Jul 2023 23:08:53 -0400 Subject: [PATCH] Fix NPE with returnFire field. (#11729) The field was marked as transient in two classes, meaning it would not be serialized and was null on deserialization, but the code did not handle it properly. Since the leaf code using it was marked with `@RemoveOnNextMajorRelease` and could handle null, simply remove the non-null tag and propagate the deprecation tag. Fixes https://github.com/triplea-game/triplea/issues/11097. --- .../delegate/battle/steps/fire/FireRoundStepsFactory.java | 6 +++++- .../triplea/delegate/battle/steps/fire/MarkCasualties.java | 2 +- .../battle/steps/fire/firststrike/DefensiveFirstStrike.java | 2 ++ .../battle/steps/fire/firststrike/OffensiveFirstStrike.java | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/game-app/game-core/src/main/java/games/strategy/triplea/delegate/battle/steps/fire/FireRoundStepsFactory.java b/game-app/game-core/src/main/java/games/strategy/triplea/delegate/battle/steps/fire/FireRoundStepsFactory.java index b08eb3d7f4b..f1f9642bb95 100644 --- a/game-app/game-core/src/main/java/games/strategy/triplea/delegate/battle/steps/fire/FireRoundStepsFactory.java +++ b/game-app/game-core/src/main/java/games/strategy/triplea/delegate/battle/steps/fire/FireRoundStepsFactory.java @@ -15,6 +15,7 @@ import java.util.stream.Collectors; import javax.annotation.Nonnull; import lombok.Builder; +import org.triplea.java.RemoveOnNextMajorRelease; /** Build the steps for the fire round (roll dice, select casualties, and mark casualties) */ @Builder @@ -24,7 +25,10 @@ public class FireRoundStepsFactory { @Nonnull final BattleActions battleActions; @Nonnull final Function> firingGroupSplitter; @Nonnull final BattleState.Side side; - @Nonnull final MustFightBattle.ReturnFire returnFire; + + @RemoveOnNextMajorRelease("This is ReturnFire.ALL or null for everything except old saves") + final MustFightBattle.ReturnFire returnFire; + @Nonnull final BiFunction diceRoller; @Nonnull final BiFunction casualtySelector; diff --git a/game-app/game-core/src/main/java/games/strategy/triplea/delegate/battle/steps/fire/MarkCasualties.java b/game-app/game-core/src/main/java/games/strategy/triplea/delegate/battle/steps/fire/MarkCasualties.java index 12d74ff8255..feacb70b0da 100644 --- a/game-app/game-core/src/main/java/games/strategy/triplea/delegate/battle/steps/fire/MarkCasualties.java +++ b/game-app/game-core/src/main/java/games/strategy/triplea/delegate/battle/steps/fire/MarkCasualties.java @@ -45,7 +45,7 @@ public class MarkCasualties implements BattleStep { private final FireRoundState fireRoundState; - @RemoveOnNextMajorRelease("This is ReturnFire.ALL for everything except old saves") + @RemoveOnNextMajorRelease("This is ReturnFire.ALL or null for everything except old saves") private final MustFightBattle.ReturnFire returnFire; @Override diff --git a/game-app/game-core/src/main/java/games/strategy/triplea/delegate/battle/steps/fire/firststrike/DefensiveFirstStrike.java b/game-app/game-core/src/main/java/games/strategy/triplea/delegate/battle/steps/fire/firststrike/DefensiveFirstStrike.java index 81375f5c38e..b08b4d486ce 100644 --- a/game-app/game-core/src/main/java/games/strategy/triplea/delegate/battle/steps/fire/firststrike/DefensiveFirstStrike.java +++ b/game-app/game-core/src/main/java/games/strategy/triplea/delegate/battle/steps/fire/firststrike/DefensiveFirstStrike.java @@ -19,6 +19,7 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +import org.triplea.java.RemoveOnNextMajorRelease; /** Generates fire steps for the first strike battle phase for the defensive player */ public class DefensiveFirstStrike implements BattleStep { @@ -39,6 +40,7 @@ private enum State { protected final State state; + @RemoveOnNextMajorRelease("This is ReturnFire.ALL or null for everything except old saves") protected transient ReturnFire returnFire = ReturnFire.ALL; public DefensiveFirstStrike(final BattleState battleState, final BattleActions battleActions) { diff --git a/game-app/game-core/src/main/java/games/strategy/triplea/delegate/battle/steps/fire/firststrike/OffensiveFirstStrike.java b/game-app/game-core/src/main/java/games/strategy/triplea/delegate/battle/steps/fire/firststrike/OffensiveFirstStrike.java index 1e2ba623e05..cd378f2bb08 100644 --- a/game-app/game-core/src/main/java/games/strategy/triplea/delegate/battle/steps/fire/firststrike/OffensiveFirstStrike.java +++ b/game-app/game-core/src/main/java/games/strategy/triplea/delegate/battle/steps/fire/firststrike/OffensiveFirstStrike.java @@ -19,6 +19,7 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +import org.triplea.java.RemoveOnNextMajorRelease; /** Generates fire steps for the first strike battle phase for the offensive player */ public class OffensiveFirstStrike implements BattleStep { @@ -39,6 +40,7 @@ private enum State { protected final State state; + @RemoveOnNextMajorRelease("This is ReturnFire.ALL or null for everything except old saves") protected transient ReturnFire returnFire = ReturnFire.ALL; public OffensiveFirstStrike(final BattleState battleState, final BattleActions battleActions) {