Skip to content

Revise StartupStep to implement AutoCloseable #35277

@Crain-32

Description

@Crain-32

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.

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions