fixing locking issue in TrackedRaceImpl.getCurrentLeg(...) which could have lead to NPEs during course updates

This commit is contained in:
Axel Uhl committed 2015-04-02 14:45:01 +02:00
1 parent c2cbc75754
commit 2e8f5dd9dd
1 file changed
+7 -1
@@ -1249,14 +1249,20 @@ public abstract class TrackedRaceImpl extends TrackedRaceWithWindEssentials impl
DummyMarkPassingWithTimePointOnly markPassingTimePoint = new DummyMarkPassingWithTimePointOnly(timePoint); DummyMarkPassingWithTimePointOnly markPassingTimePoint = new DummyMarkPassingWithTimePointOnly(timePoint);
TrackedLegOfCompetitor result = null; TrackedLegOfCompetitor result = null;
if (!competitorMarkPassings.isEmpty()) { if (!competitorMarkPassings.isEmpty()) {
final Course course = getRace().getCourse();
course.lockForRead();
try {
MarkPassing lastMarkPassingAtOfBeforeTimePoint = competitorMarkPassings.floor(markPassingTimePoint); MarkPassing lastMarkPassingAtOfBeforeTimePoint = competitorMarkPassings.floor(markPassingTimePoint);
if (lastMarkPassingAtOfBeforeTimePoint != null) { if (lastMarkPassingAtOfBeforeTimePoint != null) {
Waypoint waypointPassedLastAtOrBeforeTimePoint = lastMarkPassingAtOfBeforeTimePoint.getWaypoint(); Waypoint waypointPassedLastAtOrBeforeTimePoint = lastMarkPassingAtOfBeforeTimePoint.getWaypoint();
// don't return a leg if competitor has already finished last leg and therefore the race // don't return a leg if competitor has already finished last leg and therefore the race
if (waypointPassedLastAtOrBeforeTimePoint != getRace().getCourse().getLastWaypoint()) { if (waypointPassedLastAtOrBeforeTimePoint != course.getLastWaypoint()) {
result = getTrackedLegStartingAt(waypointPassedLastAtOrBeforeTimePoint).getTrackedLeg(competitor); result = getTrackedLegStartingAt(waypointPassedLastAtOrBeforeTimePoint).getTrackedLeg(competitor);
} }
} }
} finally {
course.unlockAfterRead();
}
} }
return result; return result;
} }