From e23e431f1026ef056549d1b14563a0f8e2228afc Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 16 Jan 2024 11:35:13 -0800 Subject: [PATCH] Polish 'Remove unreachable throw code' See gh-39107 --- .../springframework/boot/SpringApplication.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java index d760c90a35..0fc3b65d86 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java @@ -330,9 +330,6 @@ public class SpringApplication { listeners.started(context, timeTakenToStartup); callRunners(context, applicationArguments); } - catch (AbandonedRunException ex) { - throw ex; - } catch (Throwable ex) { throw handleRunFailure(context, ex, listeners); } @@ -342,9 +339,6 @@ public class SpringApplication { listeners.ready(context, timeTakenToReady); } } - catch (AbandonedRunException ex) { - throw ex; - } catch (Throwable ex) { throw handleRunFailure(context, ex, null); } @@ -790,6 +784,9 @@ public class SpringApplication { private RuntimeException handleRunFailure(ConfigurableApplicationContext context, Throwable exception, SpringApplicationRunListeners listeners) { + if (exception instanceof AbandonedRunException abandonedRunException) { + return abandonedRunException; + } try { try { handleExitCode(context, exception); @@ -808,10 +805,8 @@ public class SpringApplication { catch (Exception ex) { logger.warn("Unable to close ApplicationContext", ex); } - if (exception instanceof RuntimeException runtimeException) { - return runtimeException; - } - return new IllegalStateException(exception); + return (exception instanceof RuntimeException runtimeException) ? runtimeException + : new IllegalStateException(exception); } private Collection getExceptionReporters(ConfigurableApplicationContext context) {