From 18af8fc20ca0029d21ce2103c60cd8a69d2b955c Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Tue, 7 Jul 2026 18:46:02 +0200 Subject: [PATCH] fixing NPE in mark passing calculator when leg bearing is unknown --- .../impl/CandidateFinderImpl.java | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/impl/CandidateFinderImpl.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/impl/CandidateFinderImpl.java index f734c92fab7..629155e72b9 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/impl/CandidateFinderImpl.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/impl/CandidateFinderImpl.java @@ -1481,24 +1481,30 @@ public class CandidateFinderImpl implements CandidateFinder { // passing instructions. If no passing instructions are given, construct two lines, one to each direction // orthogonally to the adjacent leg: if (w == race.getRace().getCourse().getFirstWaypoint()) { - if (instruction == PassingInstruction.None || instruction == PassingInstruction.Single_Unknown) { - b = markPositionCache.getLegBearing(race.getTrackedLegStartingAt(w)).add(new DegreeBearingImpl(90)); - result.add(new Pair<>(p, b)); - b = markPositionCache.getLegBearing(race.getTrackedLegStartingAt(w)).add(new DegreeBearingImpl(270)); - } else { - b = markPositionCache.getLegBearing(race.getTrackedLegStartingAt(w)).add(new DegreeBearingImpl(instruction == PassingInstruction.Port ? 90 : 270)); + final Bearing legBearingStartingAtW = markPositionCache.getLegBearing(race.getTrackedLegStartingAt(w)); + if (legBearingStartingAtW != null) { + if (instruction == PassingInstruction.None || instruction == PassingInstruction.Single_Unknown) { + b = legBearingStartingAtW.add(new DegreeBearingImpl(90)); + result.add(new Pair<>(p, b)); + b = legBearingStartingAtW.add(new DegreeBearingImpl(270)); + } else { + b = legBearingStartingAtW.add(new DegreeBearingImpl(instruction == PassingInstruction.Port ? 90 : 270)); + } } } else if (w == race.getRace().getCourse().getLastWaypoint()) { - if (instruction == PassingInstruction.None || instruction == PassingInstruction.Single_Unknown) { - b = markPositionCache.getLegBearing(race.getTrackedLegFinishingAt(w)).add(new DegreeBearingImpl(90)); - result.add(new Pair<>(p, b)); - b = markPositionCache.getLegBearing(race.getTrackedLegFinishingAt(w)).add(new DegreeBearingImpl(270)); - } else { - b = markPositionCache.getLegBearing(race.getTrackedLegFinishingAt(w)).add(new DegreeBearingImpl(instruction == PassingInstruction.Port ? 90 : 270)); + final Bearing legBearingFinishingAtW = markPositionCache.getLegBearing(race.getTrackedLegFinishingAt(w)); + if (legBearingFinishingAtW != null) { + if (instruction == PassingInstruction.None || instruction == PassingInstruction.Single_Unknown) { + b = legBearingFinishingAtW.add(new DegreeBearingImpl(90)); + result.add(new Pair<>(p, b)); + b = legBearingFinishingAtW.add(new DegreeBearingImpl(270)); + } else { + b = legBearingFinishingAtW.add(new DegreeBearingImpl(instruction == PassingInstruction.Port ? 90 : 270)); + } } } else { - Bearing before = markPositionCache.getLegBearing(race.getTrackedLegFinishingAt(w)); - Bearing after = markPositionCache.getLegBearing(race.getTrackedLegStartingAt(w)); + final Bearing before = markPositionCache.getLegBearing(race.getTrackedLegFinishingAt(w)); + final Bearing after = markPositionCache.getLegBearing(race.getTrackedLegStartingAt(w)); if (before != null && after != null) { b = before.middle(after.reverse()); }