diff --git a/src/main/java/com/conveyal/gtfs/model/Entity.java b/src/main/java/com/conveyal/gtfs/model/Entity.java index 0f092c64f..29657b6e6 100644 --- a/src/main/java/com/conveyal/gtfs/model/Entity.java +++ b/src/main/java/com/conveyal/gtfs/model/Entity.java @@ -35,6 +35,7 @@ import java.sql.SQLException; import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; import java.util.Enumeration; import java.util.Iterator; import java.util.Locale; @@ -213,7 +214,7 @@ protected LocalDate getDateField(String column, boolean required) throws IOExcep if (str != null) try { dateTime = LocalDate.parse(str, DateField.GTFS_DATE_FORMATTER); checkRangeInclusive(2000, 2100, dateTime.getYear()); - } catch (IllegalArgumentException iae) { + } catch (IllegalArgumentException | DateTimeParseException e) { feed.errors.add(new DateParseError(tableName, row, column)); } return dateTime; diff --git a/src/main/java/com/conveyal/gtfs/model/Route.java b/src/main/java/com/conveyal/gtfs/model/Route.java index 1b9899dd9..c5eb05fbb 100644 --- a/src/main/java/com/conveyal/gtfs/model/Route.java +++ b/src/main/java/com/conveyal/gtfs/model/Route.java @@ -106,7 +106,8 @@ public void loadOneRow() throws IOException { r.route_branding_url = getUrlField("route_branding_url", false); r.feed = feed; r.feed_id = feed.feedId; - feed.routes.put(r.route_id, r); + // Attempting to put a null key or value will cause an NPE in BTreeMap + if (r.route_id != null) feed.routes.put(r.route_id, r); } } diff --git a/src/main/java/com/conveyal/gtfs/model/Stop.java b/src/main/java/com/conveyal/gtfs/model/Stop.java index d81b677df..25a3ce82a 100644 --- a/src/main/java/com/conveyal/gtfs/model/Stop.java +++ b/src/main/java/com/conveyal/gtfs/model/Stop.java @@ -90,8 +90,8 @@ public void loadOneRow() throws IOException { s.feed = feed; s.feed_id = feed.feedId; /* TODO check ref integrity later, this table self-references via parent_station */ - - feed.stops.put(s.stop_id, s); + // Attempting to put a null key or value will cause an NPE in BTreeMap + if (s.stop_id != null) feed.stops.put(s.stop_id, s); } } diff --git a/src/main/java/com/conveyal/gtfs/model/Trip.java b/src/main/java/com/conveyal/gtfs/model/Trip.java index 36fb0f896..416854974 100644 --- a/src/main/java/com/conveyal/gtfs/model/Trip.java +++ b/src/main/java/com/conveyal/gtfs/model/Trip.java @@ -77,7 +77,8 @@ public void loadOneRow() throws IOException { t.wheelchair_accessible = getIntField("wheelchair_accessible", false, 0, 2); t.feed = feed; t.feed_id = feed.feedId; - feed.trips.put(t.trip_id, t); + // Attempting to put a null key or value will cause an NPE in BTreeMap + if (t.trip_id != null) feed.trips.put(t.trip_id, t); /* Check referential integrity without storing references. Trip cannot directly reference Services or diff --git a/src/test/java/com/conveyal/gtfs/GTFSMainTest.java b/src/test/java/com/conveyal/gtfs/GTFSMainTest.java index 4220eaeb5..2c1671922 100644 --- a/src/test/java/com/conveyal/gtfs/GTFSMainTest.java +++ b/src/test/java/com/conveyal/gtfs/GTFSMainTest.java @@ -18,6 +18,7 @@ */ public class GTFSMainTest { private static String simpleGtfsZipFileName; + private static String badGtfsZipFileName; private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); // this is used so that it is possible to test code that calls System.exit() @@ -30,6 +31,7 @@ public static void setUpClass() { simpleGtfsZipFileName = null; try { simpleGtfsZipFileName = TestUtils.zipFolderFiles("fake-agency", true); + badGtfsZipFileName = TestUtils.zipFolderFiles("fake-agency-bad-calendar-date", true); } catch (IOException e) { e.printStackTrace(); } @@ -76,4 +78,15 @@ public void canValidateSimpleAgency() throws Exception { String[] args = {simpleGtfsZipFileName, "-validate"}; GTFSMain.main(args); } + + /** + * Verify that a simple GTFS Zip file can be loaded with the GTFSMain class. + * + * @throws Exception + */ + @Test + public void canValidateFeedWithErrors() throws Exception { + String[] args = {badGtfsZipFileName, "-validate"}; + GTFSMain.main(args); + } } diff --git a/src/test/resources/fake-agency-bad-calendar-date/routes.txt b/src/test/resources/fake-agency-bad-calendar-date/routes.txt index 35ea7aa67..d414aa459 100755 --- a/src/test/resources/fake-agency-bad-calendar-date/routes.txt +++ b/src/test/resources/fake-agency-bad-calendar-date/routes.txt @@ -1,2 +1,7 @@ agency_id,route_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color,route_branding_url 1,1,1,Route 1,,3,,7CE6E7,FFFFFF, + + + + +