Recently I found myself writing some code that needed to leverage StartupStep, and found the explicit end() call to result in some painful handling. While I could (and in hindsight probably should) create a PR without an issue to do this, figured it would be better to check if the following change to StartupStep would be welcome.
public interface StartupStep extends AutoCloseable {
// Note, all the other methods have been removed for brevity, only the changes are shown.
void end();
@Override
default void close() throws Exception {
this.end();
}
}
This would let the following code work,
public void customPostProcessing(SomeBeanInstance bean, ApplicationStartup startup) {
try(var step = startup.start(bean.getName())) {
step.tag("myTag", "myValue");
dostuff(bean);
} catch (CustomException ce) { ... }
}
Where before if you wanted to call end() and handle exceptions, you'd have to ensure the StartupStep's scope would work for that.
Comment From: bclozel
Thanks very much @Crain-32 for the idea, this is a nice improvement. Sorry for the delayed feedback due to summer PTOs, I went ahead and pushed a minimal change.