This is something I see in Spring Boot code for example (in the catch block with webServer variable):
@Override
public final void refresh() throws BeansException, IllegalStateException {
try {
super.refresh();
}
catch (RuntimeException ex) {
WebServer webServer = this.webServer;
if (webServer != null) {
webServer.stop();
}
throw ex;
}
}
Why not just doing this.webServer.stop()?
What is the purpose of local variable webServer?
webServerisnullit will throw an NPE.this.webserveris not null anyway