Prevent 'Recursive update' exceptions with Restarter

Update `Restarter` to prevent 'Recursive update' `IllegalStateException`
from being thrown. Calls to `objectFactory.getObject()` now happen
outside of `computeIfAbsent`.

Fixes gh-41571
This commit is contained in:
Phillip Webb
2024-09-03 12:07:33 -07:00
parent 978ee338a8
commit aeafa20727
2 changed files with 22 additions and 4 deletions

View File

@@ -440,7 +440,12 @@ public class Restarter {
}
public Object getOrAddAttribute(String name, final ObjectFactory<?> objectFactory) {
return this.attributes.computeIfAbsent(name, (ignore) -> objectFactory.getObject());
Object value = this.attributes.get(name);
if (value == null) {
value = objectFactory.getObject();
this.attributes.put(name, value);
}
return value;
}
public Object removeAttribute(String name) {