diff --git a/service/terraform-plugin/src/main/java/com/solace/maas/ep/event/management/agent/plugin/terraform/manager/TerraformLogProcessingService.java b/service/terraform-plugin/src/main/java/com/solace/maas/ep/event/management/agent/plugin/terraform/manager/TerraformLogProcessingService.java index dd4ce055..636b05f4 100644 --- a/service/terraform-plugin/src/main/java/com/solace/maas/ep/event/management/agent/plugin/terraform/manager/TerraformLogProcessingService.java +++ b/service/terraform-plugin/src/main/java/com/solace/maas/ep/event/management/agent/plugin/terraform/manager/TerraformLogProcessingService.java @@ -10,6 +10,7 @@ import org.springframework.util.CollectionUtils; import java.time.OffsetDateTime; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -48,19 +49,21 @@ public CommandResult buildTfStateFileDeletionFailureResult(RuntimeException root .build(); } - public CommandResult buildTfCommandResult(List jsonLogs) { + public CommandResult buildTfCommandResult(List logsInJsonFormat) { - if (CollectionUtils.isEmpty(jsonLogs)) { + if (CollectionUtils.isEmpty(logsInJsonFormat)) { throw new IllegalArgumentException("No terraform logs were collected. Unable to process response."); } - List> successLogs = jsonLogs.stream() + // Copy the list to avoid modifying the original and to avoid concurrent modification exceptions + List jsonLogsCopy = new ArrayList<>(logsInJsonFormat); + List> successLogs = jsonLogsCopy.stream() .map(this::parseTfOutput) .filter(this::isApplyCompleteLog) .map(this::simplifyApplyCompleteLog) .toList(); - List> errorLogs = jsonLogs.stream() + List> errorLogs = jsonLogsCopy.stream() .map(this::parseTfOutput) .filter(this::isErrorLog) .map(this::simplifyApplyErroredLog)