Skip to content

Commit

Permalink
Fix intermittent ConcurrentModificationException thrown from codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
zoewangg committed Jan 20, 2025
1 parent 67bf542 commit 09ef3eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import software.amazon.awssdk.codegen.internal.Jackson;
import software.amazon.awssdk.codegen.internal.Utils;
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
import software.amazon.awssdk.utils.Logger;

public class CodeGenerator {

private static final Logger log = Logger.loggerFor(CodeGenerator.class);
private static final String MODEL_DIR_NAME = "models";

private final C2jModels models;
Expand Down Expand Up @@ -85,6 +86,7 @@ public void execute() {
emitCode(intermediateModel);

} catch (Exception e) {
log.error(() -> "Failed to generate code. ", e);
throw new RuntimeException(
"Failed to generate code. Exception message : " + e.getMessage(), e);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import software.amazon.awssdk.checksums.DefaultChecksumAlgorithm;
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
import software.amazon.awssdk.codegen.model.intermediate.MemberModel;
Expand Down Expand Up @@ -141,11 +142,12 @@ private static void configureRequestChecksumCalculation(OperationModel operation
* with the fastest-to-calculate algorithms first.
*/
private static void addResponseAlgorithmsCodeBlock(List<String> responseAlgorithms, CodeBlock.Builder codeBuilder) {
responseAlgorithms.sort(Comparator.comparingInt(o -> CHECKSUM_ALGORITHM_PRIORITY.getOrDefault(
o.toUpperCase(Locale.US), Integer.MAX_VALUE)));
List<String> sortedResponseAlgorithms =
responseAlgorithms.stream().sorted(Comparator.comparingInt(o -> CHECKSUM_ALGORITHM_PRIORITY.getOrDefault(
o.toUpperCase(Locale.US), Integer.MAX_VALUE))).collect(Collectors.toList());

codeBuilder.add(CodeBlock.of(".responseAlgorithmsV2("));
List<CodeBlock> responseAlgorithmsCodeBlocks = responseAlgorithmsCodeBlocks(responseAlgorithms);
List<CodeBlock> responseAlgorithmsCodeBlocks = responseAlgorithmsCodeBlocks(sortedResponseAlgorithms);
for (int i = 0; i < responseAlgorithmsCodeBlocks.size(); i++) {
CodeBlock code = responseAlgorithmsCodeBlocks.get(i);
codeBuilder.add(code);
Expand Down

0 comments on commit 09ef3eb

Please sign in to comment.