From 99dc7914b2e83968f95f7b2d37aff6268e0c0bde Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 17 Sep 2020 01:41:39 -0700 Subject: [PATCH] Attempt to fix ConcurrentModificationException Attempt to fix `ConcurrentModificationException` which occurs on Java 11+. See gh-23326 --- .../org/springframework/boot/DefaultBootstrapContext.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/DefaultBootstrapContext.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/DefaultBootstrapContext.java index 9806d34916..79495c0c95 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/DefaultBootstrapContext.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/DefaultBootstrapContext.java @@ -88,7 +88,12 @@ public class DefaultBootstrapContext implements ConfigurableBootstrapContext { synchronized (this.instanceSuppliers) { InstanceSupplier instanceSupplier = this.instanceSuppliers.get(type); Assert.state(instanceSupplier != null, () -> type.getName() + " has not been registered"); - return (T) this.instances.computeIfAbsent(type, (key) -> instanceSupplier.get(this)); + T instance = (T) this.instances.get(type); + if (instance == null) { + instance = (T) instanceSupplier.get(this); + this.instances.put(type, instance); + } + return instance; } }