Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix intermittent ConcurrentModificationException thrown from codegen #5812

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading