Skip to content

Commit

Permalink
Handle null pointer exception when no next stop is found from the trip
Browse files Browse the repository at this point in the history
  • Loading branch information
mjaakko committed Apr 19, 2023
1 parent fde7f23 commit edf1aa6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/kotlin/fi/hsl/gtfsrt2hfp/GtfsRtToHfpConverter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down

0 comments on commit edf1aa6

Please sign in to comment.