Skip to content

Commit b37cf70

Browse files
committed
temporary solution for NullPointerExceptions during GTFS file processing
1 parent d733d74 commit b37cf70

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

siri/siri-client/src/main/java/il/org/hasadna/siri_client/gtfs/analysis/GtfsDataManipulations.java

+11
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99

1010
import il.org.hasadna.siri_client.gtfs.crud.*;
1111
import il.org.hasadna.siri_client.gtfs.crud.Calendar;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
1214

1315
public class GtfsDataManipulations {
1416

17+
private static Logger logger = LoggerFactory.getLogger(GtfsDataManipulations.class);
18+
1519
private GtfsCrud gtfsCrud;
1620

1721
private Map<ServiceId, Calendar> calendars;
@@ -123,6 +127,7 @@ public Collection<GtfsRecord> combineForSpecificRoute(LocalDate date, String rou
123127
}
124128

125129
private GtfsRecord createGtfsRecord(Trip currTrip) {
130+
try {
126131
Calendar currCalendar = getCalendars().get(currTrip.getServiceId());
127132

128133
List<StopTime> tmpStopTimes = getStopTimes().get(currTrip.getTripId());
@@ -133,6 +138,12 @@ private GtfsRecord createGtfsRecord(Trip currTrip) {
133138
StopTime currFirstStopTime = tmpStopTimes.stream().min(Comparator.comparing(StopTime::getStopSequence)).get();
134139
Stop currFirstStop = getStops().get(currFirstStopTime.getStopId());
135140
return new GtfsRecord(currTrip, currCalendar, currFirstStopTime, currFirstStop, currLastStopTime, currLastStop);
141+
}
142+
catch (Exception ex) {
143+
logger.error("unexpected exception in createGtfsRecord", ex);
144+
logger.error("currTrip: {}", currTrip.toString());
145+
return null;
146+
}
136147
}
137148

138149
}

siri/siri-client/src/main/java/il/org/hasadna/siri_client/gtfs/analysis/SchedulingDataCreator.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@ public SchedulingDataCreator() {
3131
Function<GtfsRecord, String> f = new Function<GtfsRecord, String>() {
3232
@Override
3333
public String apply(GtfsRecord gtfsRecord) {
34-
return gtfsRecord.getTrip().getRouteId();
34+
if (gtfsRecord != null) {
35+
return gtfsRecord.getTrip().getRouteId();
36+
}
37+
else {
38+
logger.warn("null gtfsRecord!");
39+
// returning some dummy routeId. So grouping will work, and all failed records will be grouped to routeId "99999999"
40+
// which does not exist anyway
41+
return "99999999999";
42+
}
3543
}
3644
};
3745

0 commit comments

Comments
 (0)