Skip to content

Commit

Permalink
Fixed a bug in AttributeMap, which causes a ConcurrentModificationExc…
Browse files Browse the repository at this point in the history
…eption when lazy properties depend on lazy properties that depend on any other property.

This is achieved by changing a `compute` into a `get` followed by a `put`.
  • Loading branch information
millems committed Sep 9, 2024
1 parent a117b2a commit c96bef3
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions utils/src/main/java/software/amazon/awssdk/utils/AttributeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ private void internalPut(Key<?> key, Value<?> value) {
if (oldValue != null) {
dependencyGraph.valueUpdated(oldValue, value);
}

}

/**
Expand All @@ -327,17 +328,17 @@ private void internalPut(Key<?> key, Value<?> value) {
*/
private Value<?> internalComputeIfAbsent(Key<?> key, Supplier<Value<?>> value) {
checkCopyOnUpdate();
return attributes.compute(key, (k, v) -> {
if (v == null || resolveValue(v) == null) {
Value<?> newValue = value.get();
Validate.notNull(newValue, "Supplied value must not be null.");
if (v != null) {
dependencyGraph.valueUpdated(v, newValue);
}
return newValue;
Value<?> currentValue = attributes.get(key);
if (currentValue == null || resolveValue(currentValue) == null) {
Value<?> newValue = value.get();
Validate.notNull(newValue, "Supplied value must not be null.");
if (currentValue != null) {
dependencyGraph.valueUpdated(currentValue, newValue);
}
return v;
});
attributes.put(key, newValue);
return newValue;
}
return currentValue;
}

private void checkCopyOnUpdate() {
Expand Down

0 comments on commit c96bef3

Please sign in to comment.