Skip to content

Commit cbcc884

Browse files
authored
fix null pointer when storing platform sensors (opendcs#407)
platform sensors need to reference their platform
1 parent df4ae36 commit cbcc884

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

opendcs-rest-api/src/main/java/org/opendcs/odcsapi/res/PlatformResources.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ static Platform map(ApiPlatform platform) throws DatabaseException
367367
ret.setPlatformDesignator(platform.getDesignator());
368368
ret.lastModifyTime = new Date();
369369
ret.platformSensors = platMap(platform.getPlatformSensors());
370+
ret.platformSensors.forEach(p -> p.platform = ret);
370371
if (platform.getConfigId() != null)
371372
{
372373
PlatformConfig config = new PlatformConfig();

opendcs-rest-api/src/test/java/org/opendcs/odcsapi/res/PlatformResourcesTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import static org.junit.jupiter.api.Assertions.assertFalse;
4040
import static org.junit.jupiter.api.Assertions.assertNotNull;
4141
import static org.junit.jupiter.api.Assertions.assertNull;
42+
import static org.junit.jupiter.api.Assertions.assertSame;
4243
import static org.mockito.ArgumentMatchers.any;
4344
import static org.mockito.Mockito.doAnswer;
4445
import static org.mockito.Mockito.when;
@@ -362,6 +363,7 @@ void testApiPlatformMap() throws Exception
362363
assertMatch(plat.getPlatformSensors(), result.getPlatformSensors());
363364
assertMatchMedium(plat.getTransportMedia(), result.getTransportMedia());
364365
assertEquals(plat.getProperties(), result.getProperties());
366+
result.platformSensors.forEach(s -> assertSame(result, s.platform));
365367
}
366368

367369
private static void assertMatch(List<ApiPlatformSensor> apiPlatformSensors, Iterator<PlatformSensor> platformSensors)

0 commit comments

Comments
 (0)