Skip to content

Commit 99dc791

Browse files
committed
Attempt to fix ConcurrentModificationException
Attempt to fix `ConcurrentModificationException` which occurs on Java 11+. See gh-23326
1 parent cad079c commit 99dc791

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/DefaultBootstrapContext.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ public <T> T get(Class<T> type) throws IllegalStateException {
8888
synchronized (this.instanceSuppliers) {
8989
InstanceSupplier<?> instanceSupplier = this.instanceSuppliers.get(type);
9090
Assert.state(instanceSupplier != null, () -> type.getName() + " has not been registered");
91-
return (T) this.instances.computeIfAbsent(type, (key) -> instanceSupplier.get(this));
91+
T instance = (T) this.instances.get(type);
92+
if (instance == null) {
93+
instance = (T) instanceSupplier.get(this);
94+
this.instances.put(type, instance);
95+
}
96+
return instance;
9297
}
9398
}
9499

0 commit comments

Comments
 (0)