From edf1aa66ecc94a4ef3123e364a07ac989abfd635 Mon Sep 17 00:00:00 2001 From: Jaakko Malkki Date: Wed, 19 Apr 2023 10:42:45 +0300 Subject: [PATCH] Handle null pointer exception when no next stop is found from the trip --- src/main/kotlin/fi/hsl/gtfsrt2hfp/GtfsRtToHfpConverter.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/fi/hsl/gtfsrt2hfp/GtfsRtToHfpConverter.kt b/src/main/kotlin/fi/hsl/gtfsrt2hfp/GtfsRtToHfpConverter.kt index 21bff3f..6e91dba 100644 --- a/src/main/kotlin/fi/hsl/gtfsrt2hfp/GtfsRtToHfpConverter.kt +++ b/src/main/kotlin/fi/hsl/gtfsrt2hfp/GtfsRtToHfpConverter.kt @@ -127,7 +127,12 @@ class GtfsRtToHfpConverter(private val operatorId: String, tripIdCacheDuration: } ) - val firstPossibleNextStop = stopTimesB.find { stopTime -> stopTime.stopSequence == vehicle.currentStopSequence } + val firstPossibleNextStop = stopTimesB.find { stopTime -> stopTime.stopSequence >= vehicle.currentStopSequence } + if (firstPossibleNextStop == null) { + log.warn { "No next possible stop found for vehicle ${vehicle.vehicle.id}, stop seq: ${vehicle.currentStopSequence}, stops of the trip: ${stopTimesB.joinToString { "${it.stopSequence}: ${it.stopId}" }}" } + return null + } + //Add stops that are before the next stop in GTFS-RT to visited stops list stopTimesB.headSet(firstPossibleNextStop, false).map { it.stopId }.forEach { visitedStopsCache.addVisitedStop(uniqueVehicleId, tripId, it) }