OneBusAway / onebusaway-gtfs-modules

A Java-based library for reading, writing, and transforming public transit data in the GTFS format, including database support.
Other
129 stars 107 forks source link

MissingRequiredFieldException thrown on transfers.txt transfer_type, which can be empty #90

Closed barbeau closed 7 years ago

barbeau commented 7 years ago

Summary:

We're using the oba-gtfs-modules in the gtfs-realtime-validator (see related issue https://github.com/CUTR-at-USF/gtfs-realtime-validator/issues/309).

When trying to load BURT (Burlington, ON, Canada) GTFS data (https://github.com/CUTR-at-USF/gtfs-realtime-validator/files/1458082/gtfs.zip), the modules throw this exception:

Exception in thread "main" org.onebusaway.csv_entities.exceptions.CsvEntityIOException: io error: entityType=org.onebusaway.gtfs.model.Transfer path=transfers.txt lineNumber=2
    at org.onebusaway.csv_entities.CsvEntityReader.readEntities(CsvEntityReader.java:161)
    at org.onebusaway.csv_entities.CsvEntityReader.readEntities(CsvEntityReader.java:120)
    at org.onebusaway.csv_entities.CsvEntityReader.readEntities(CsvEntityReader.java:115)
    at org.onebusaway.gtfs.serialization.GtfsReader.run(GtfsReader.java:174)
    at org.onebusaway.gtfs.serialization.GtfsReader.run(GtfsReader.java:162)
    at edu.usf.cutr.gtfsrtvalidator.lib.batch.BatchProcessor.readGtfsData(BatchProcessor.java:312)
    at edu.usf.cutr.gtfsrtvalidator.lib.batch.BatchProcessor.processFeeds(BatchProcessor.java:138)
    at edu.usf.cutr.gtfsrtvalidator.lib.Main.main(Main.java:62)
Caused by: org.onebusaway.csv_entities.exceptions.MissingRequiredFieldException: missing required field: transfer_type
    at org.onebusaway.csv_entities.schema.AbstractFieldMapping.isMissingAndOptional(AbstractFieldMapping.java:100)
    at org.onebusaway.csv_entities.schema.DefaultFieldMapping.translateFromCSVToObject(DefaultFieldMapping.java:43)
    at org.onebusaway.csv_entities.IndividualCsvEntityReader.readEntity(IndividualCsvEntityReader.java:131)
    at org.onebusaway.csv_entities.IndividualCsvEntityReader.handleLine(IndividualCsvEntityReader.java:98)
    at org.onebusaway.csv_entities.CsvEntityReader.readEntities(CsvEntityReader.java:157)
    ... 7 more

The problem is that while transfers.txt transfer_type is a required field, it is allowed to be empty (i.e., the header must exist, but the value in the rows can be omitted).

https://developers.google.com/transit/gtfs/reference/#transferstxt says:

  • 0 or (empty) - This is a recommended transfer point between routes.

Steps to reproduce:

Load the BURT GTFS data (https://github.com/CUTR-at-USF/gtfs-realtime-validator/files/1458082/gtfs.zip), like:

       String path = "gtfs.zip";
       File mPathToGtfsFile = new File(path);
        _log.info("Reading GTFS data from " + mPathToGtfsFile + "...");
        GtfsDaoImpl mGtfsData = new GtfsDaoImpl();
        GtfsReader mReader = new GtfsReader();
        mReader.setInputLocation(mPathToGtfsFile);
        mReader.setEntityStore(mGtfsData);
        long startGtfsRead = System.nanoTime();
        mReader.run();

Expected behavior:

Load the GTFS data without error

Observed behavior:

I get crash with stack trace above

Platform:

Windows 7 Enterprise w/ jdk1.8.0_73 and:

<groupId>org.onebusaway</groupId>
<artifactId>onebusaway-gtfs</artifactId>
<version>1.3.17</version>