From 679cdeb2c64b29fa4a7285ed0d3608604c2f1578 Mon Sep 17 00:00:00 2001 From: sleet01 Date: Mon, 25 Sep 2023 12:07:43 -0700 Subject: [PATCH 1/2] Fix #4790: uncaught NPE when Sniper Turret fired on fleeing off-board target --- .../weapons/ArtilleryWeaponIndirectFireHandler.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/megamek/src/megamek/common/weapons/ArtilleryWeaponIndirectFireHandler.java b/megamek/src/megamek/common/weapons/ArtilleryWeaponIndirectFireHandler.java index 94874ec89b5..b33e9c21f03 100644 --- a/megamek/src/megamek/common/weapons/ArtilleryWeaponIndirectFireHandler.java +++ b/megamek/src/megamek/common/weapons/ArtilleryWeaponIndirectFireHandler.java @@ -103,7 +103,16 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { } final Vector spottersBefore = aaa.getSpotterIds(); - Coords targetPos = target.getPosition(); + + // Handle counter-battery on fleeing/fled off-board targets. + Coords targetPos; + try { + targetPos = target.getPosition(); + } catch (Exception e) { + LogManager.getLogger().error(String.format("Artillery Target %s is missing; off-board target fled?", waa.getTargetId())); + return false; + } + final int playerId = aaa.getPlayerId(); boolean targetIsEntity = target.getTargetType() == Targetable.TYPE_ENTITY; boolean targetIsAirborneVTOL = targetIsEntity && target.isAirborneVTOLorWIGE(); From a4109f82e24fad8409a6ad6d1f2dc68e5b621d0c Mon Sep 17 00:00:00 2001 From: sleet01 Date: Mon, 25 Sep 2023 22:23:12 -0700 Subject: [PATCH 2/2] Simplify handling of missing off-board target entity --- .../common/weapons/ArtilleryWeaponIndirectFireHandler.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/megamek/src/megamek/common/weapons/ArtilleryWeaponIndirectFireHandler.java b/megamek/src/megamek/common/weapons/ArtilleryWeaponIndirectFireHandler.java index b33e9c21f03..6676e4908c3 100644 --- a/megamek/src/megamek/common/weapons/ArtilleryWeaponIndirectFireHandler.java +++ b/megamek/src/megamek/common/weapons/ArtilleryWeaponIndirectFireHandler.java @@ -104,11 +104,10 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { final Vector spottersBefore = aaa.getSpotterIds(); + Coords targetPos = target.getPosition(); + // Handle counter-battery on fleeing/fled off-board targets. - Coords targetPos; - try { - targetPos = target.getPosition(); - } catch (Exception e) { + if (null == targetPos) { LogManager.getLogger().error(String.format("Artillery Target %s is missing; off-board target fled?", waa.getTargetId())); return false; }