Skip to content

Commit 74a0147

Browse files
mdeinumbclozel
authored andcommitted
Call StartupStep.end in finally block
Prior to this commit it was possible that a StartupStep was started but never ended. This was the case when an exception occured during bean initializing. To always call the method regardless of the outcome, the call to StartupStep.end has been moved to a finally block. When an exception occurs the StartupStep is also enriched with the exception class and message for diagnostic purposes. See gh-22776 Closes gh-25572
1 parent 7adeb46 commit 74a0147

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ else if (requiredType != null) {
300300
markBeanAsCreated(beanName);
301301
}
302302

303+
StartupStep beanCreation = this.applicationStartup.start("spring.beans.instantiate")
304+
.tag("beanName", name);
303305
try {
304-
StartupStep beanCreation = this.applicationStartup.start("spring.beans.instantiate")
305-
.tag("beanName", name);
306306
if (requiredType != null) {
307307
beanCreation.tag("beanType", requiredType::toString);
308308
}
@@ -383,12 +383,16 @@ else if (mbd.isPrototype()) {
383383
throw new ScopeNotActiveException(beanName, scopeName, ex);
384384
}
385385
}
386-
beanCreation.end();
387386
}
388387
catch (BeansException ex) {
388+
beanCreation.tag("exception", ex.getClass().toString());
389+
beanCreation.tag("message", ex.getMessage());
389390
cleanupAfterBeanCreationFailure(beanName);
390391
throw ex;
391392
}
393+
finally {
394+
beanCreation.end();
395+
}
392396
}
393397

394398
// Check if required type matches the type of the actual bean instance.

0 commit comments

Comments
 (0)