Skip to content

Commit 1852cd5

Browse files
fix(MtcFeedResource): Avoid NullPointerException if ExternalFeedSourceProperty->AgencyId is set to n
1 parent eddd745 commit 1852cd5

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/main/java/com/conveyal/datatools/manager/extensions/mtc/MtcFeedResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public void feedVersionCreated(
193193
constructId(feedVersion.parentFeedSource(), this.getResourceType(), AGENCY_ID_FIELDNAME)
194194
);
195195

196-
if(agencyIdProp == null || agencyIdProp.value.equals("null")) {
196+
if(agencyIdProp == null || agencyIdProp.value == null || agencyIdProp.value.equals("null")) {
197197
LOG.error("Could not read {} for FeedSource {}", AGENCY_ID_FIELDNAME, feedVersion.feedSourceId);
198198
return;
199199
}

src/test/java/com/conveyal/datatools/manager/extensions/mtc/MtcFeedResourceTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.conveyal.datatools.UnitTest;
55
import com.conveyal.datatools.manager.models.ExternalFeedSourceProperty;
66
import com.conveyal.datatools.manager.models.FeedSource;
7+
import com.conveyal.datatools.manager.models.FeedVersion;
78
import com.conveyal.datatools.manager.models.Project;
89
import com.conveyal.datatools.manager.persistence.Persistence;
910
import com.fasterxml.jackson.databind.JsonNode;
@@ -15,7 +16,9 @@
1516
import java.io.IOException;
1617
import java.util.Date;
1718

19+
import static com.conveyal.datatools.TestUtils.createFeedVersion;
1820
import static com.conveyal.datatools.TestUtils.parseJson;
21+
import static com.conveyal.datatools.TestUtils.zipFolderFiles;
1922
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
2023
import static com.github.tomakehurst.wiremock.client.WireMock.get;
2124
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
@@ -27,6 +30,7 @@
2730
import static org.hamcrest.Matchers.equalTo;
2831
import static org.hamcrest.Matchers.notNullValue;
2932
import static org.hamcrest.Matchers.nullValue;
33+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
3034

3135
class MtcFeedResourceTest extends UnitTest {
3236
private static Project project;
@@ -152,4 +156,23 @@ void canUpdateFeedExternalPropertiesToMongo() throws IOException {
152156
ExternalFeedSourceProperty removedPublicIdProp = Persistence.externalFeedSourceProperties.getById(agencyPublicIdProp.id);
153157
assertThat(removedPublicIdProp, nullValue());
154158
}
159+
160+
@Test
161+
void shouldTolerateNullObjectInExternalPropertyAgencyId() throws IOException {
162+
// Add an entry in the ExternalFeedSourceProperties collection
163+
// with AgencyId value set to null.
164+
ExternalFeedSourceProperty agencyIdProp = new ExternalFeedSourceProperty(
165+
feedSource,
166+
"MTC",
167+
"AgencyId",
168+
null
169+
);
170+
agencyIdProp.feedSourceId = feedSource.id;
171+
Persistence.externalFeedSourceProperties.create(agencyIdProp);
172+
173+
// Trigger the feed update process (it should not upload anything to S3).
174+
FeedVersion feedVersion = createFeedVersion(feedSource, zipFolderFiles("mini-bart-new"));
175+
MtcFeedResource mtcFeedResource = new MtcFeedResource();
176+
assertDoesNotThrow(() -> mtcFeedResource.feedVersionCreated(feedVersion, null));
177+
}
155178
}

0 commit comments

Comments
 (0)