Skip to content

Commit 31e1676

Browse files
leonardehrenfriedoptionsome
authored andcommitted
Fix NPE when having feeds with and without emissions.txt
1 parent 0629294 commit 31e1676

2 files changed

Lines changed: 4 additions & 15 deletions

File tree

application/src/ext/java/org/opentripplanner/ext/emissions/Co2EmissionsDataReader.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ public Map<FeedScopedId, Double> read(CompositeDataSource catalog, String resolv
3535
try {
3636
var emissionsDataSource = catalog.entry(EMISSIONS_FILE_NAME);
3737

38-
if (emissionsDataSource.exists()) {
38+
if (emissionsDataSource != null && emissionsDataSource.exists()) {
3939
return readEmissions(emissionsDataSource.asInputStream(), resolvedFeedId);
4040
} else {
4141
return Map.of();
4242
}
4343
} catch (IOException e) {
44-
LOG.error("Failed to read emission data. Details: " + e.getMessage(), e);
44+
LOG.error("Failed to read emission data. Details: {}", e.getMessage(), e);
4545
return Map.of();
4646
}
4747
}
@@ -100,19 +100,6 @@ private Map<FeedScopedId, Double> readEmissions(InputStream stream, String feedI
100100
return emissionsData;
101101
}
102102

103-
private String readFeedId(InputStream stream) {
104-
try {
105-
CsvReader reader = new CsvReader(stream, StandardCharsets.UTF_8);
106-
reader.readHeaders();
107-
reader.readRecord();
108-
return reader.get("feed_id");
109-
} catch (IOException e) {
110-
issueStore.add("InvalidEmissionData", "Reading feed_info.txt failed.");
111-
LOG.error("InvalidEmissionData: reading feed_info.txt failed.", e);
112-
throw new RuntimeException(e);
113-
}
114-
}
115-
116103
private Optional<Double> calculateEmissionsPerPassengerPerMeter(
117104
String routeId,
118105
double avgCo2PerVehiclePerMeter,

application/src/main/java/org/opentripplanner/datastore/api/CompositeDataSource.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.Closeable;
44
import java.util.Collection;
5+
import javax.annotation.Nullable;
56

67
/**
78
* A composite data source contain a collection of other {@link DataSource}s.
@@ -24,6 +25,7 @@ public interface CompositeDataSource extends DataSource, Closeable {
2425
* <p>
2526
* {@code DataSource routesSrc = gtfsSource.entry("routes.txt")}
2627
*/
28+
@Nullable
2729
DataSource entry(String name);
2830

2931
/**

0 commit comments

Comments
 (0)