From 6ab069a12902b040c38cfa856d6457d3a68389ab Mon Sep 17 00:00:00 2001 From: FranckLecuyer <47824306+FranckLecuyer@users.noreply.github.com> Date: Thu, 3 Oct 2024 13:54:44 +0200 Subject: [PATCH] Fix npe when reporterId is null (#540) Signed-off-by: Franck LECUYER --- .../server/NetworkModificationController.java | 2 +- .../server/ModificationControllerTest.java | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java b/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java index ac91b8ab0..b8e6bddce 100644 --- a/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java +++ b/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java @@ -288,6 +288,6 @@ public ResponseEntity> applyModifications(@P @Parameter(description = "the report uuid") @RequestParam(value = "reportUuid", required = false) UUID reportUuid, @Parameter(description = "the reporter id") @RequestParam(value = "reporterId", required = false) String reporterId, @RequestBody List modificationsUuidList) { - return ResponseEntity.ok().body(networkModificationService.applyModificationsFromUuids(networkUuid, variantId, new ReportInfos(reportUuid, UUID.fromString(reporterId)), modificationsUuidList)); + return ResponseEntity.ok().body(networkModificationService.applyModificationsFromUuids(networkUuid, variantId, new ReportInfos(reportUuid, reporterId != null ? UUID.fromString(reporterId) : null), modificationsUuidList)); } } diff --git a/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java b/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java index a562f4623..ee2c5bafa 100644 --- a/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java +++ b/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java @@ -1634,10 +1634,10 @@ public void testApplyModificationsFromUuids() throws Exception { assertNotNull(sw); assertFalse(sw.isOpen()); // switch is closed - // apply the modification on the network + // apply the modification on the network with a reporterId mvcResult = mockMvc.perform( put("/v1/networks/" + TEST_NETWORK_ID + "/apply" - + "?variantId=" + NetworkCreation.VARIANT_ID + "&reporterId=" + UUID.randomUUID().toString()) + + "?variantId=" + NetworkCreation.VARIANT_ID + "&reporterId=" + UUID.randomUUID()) .content(objectWriter.writeValueAsString(modificationUuidList)) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andReturn(); @@ -1651,5 +1651,14 @@ public void testApplyModificationsFromUuids() throws Exception { assertEquals(modificationUuidList, newModificationUuidList); assertTrue(sw.isOpen()); // switch is opened + + // apply the modification on the network without reporterId + mvcResult = mockMvc.perform( + put("/v1/networks/" + TEST_NETWORK_ID + "/apply" + + "?variantId=" + NetworkCreation.VARIANT_ID) + .content(objectWriter.writeValueAsString(modificationUuidList)) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andReturn(); + assertApplicationStatusOK(mvcResult); } }