Skip to content

Commit

Permalink
Merge pull request #213 from SolaceProducts/DATAGO-90245-bug-fix
Browse files Browse the repository at this point in the history
DATAGO-90245: BUG: Prevent `ConcurrentModificationException` by making making a copy of the list before operating on it
  • Loading branch information
rudraneel-chakraborty authored Dec 4, 2024
2 parents b1379c1 + 4afb13a commit fcb35af
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -48,19 +49,21 @@ public CommandResult buildTfStateFileDeletionFailureResult(RuntimeException root
.build();
}

public CommandResult buildTfCommandResult(List<String> jsonLogs) {
public CommandResult buildTfCommandResult(List<String> logsInJsonFormat) {

if (CollectionUtils.isEmpty(jsonLogs)) {
if (CollectionUtils.isEmpty(logsInJsonFormat)) {
throw new IllegalArgumentException("No terraform logs were collected. Unable to process response.");
}

List<Map<String, Object>> successLogs = jsonLogs.stream()
// Copy the list to avoid modifying the original and to avoid concurrent modification exceptions
List<String> jsonLogsCopy = new ArrayList<>(logsInJsonFormat);
List<Map<String, Object>> successLogs = jsonLogsCopy.stream()
.map(this::parseTfOutput)
.filter(this::isApplyCompleteLog)
.map(this::simplifyApplyCompleteLog)
.toList();

List<Map<String, Object>> errorLogs = jsonLogs.stream()
List<Map<String, Object>> errorLogs = jsonLogsCopy.stream()
.map(this::parseTfOutput)
.filter(this::isErrorLog)
.map(this::simplifyApplyErroredLog)
Expand Down

0 comments on commit fcb35af

Please sign in to comment.