Attempt to fix ConcurrentModificationException

Attempt to fix `ConcurrentModificationException` which occurs on
Java 11+.

See gh-23326
This commit is contained in:
Phillip Webb
2020-09-17 01:41:39 -07:00
parent cad079ce7d
commit 99dc7914b2

View File

@@ -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;
}
}