Skip to content

Commit e23e431

Browse files
committed
Polish 'Remove unreachable throw code'
See gh-39107
1 parent a4ae660 commit e23e431

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,6 @@ public ConfigurableApplicationContext run(String... args) {
330330
listeners.started(context, timeTakenToStartup);
331331
callRunners(context, applicationArguments);
332332
}
333-
catch (AbandonedRunException ex) {
334-
throw ex;
335-
}
336333
catch (Throwable ex) {
337334
throw handleRunFailure(context, ex, listeners);
338335
}
@@ -342,9 +339,6 @@ public ConfigurableApplicationContext run(String... args) {
342339
listeners.ready(context, timeTakenToReady);
343340
}
344341
}
345-
catch (AbandonedRunException ex) {
346-
throw ex;
347-
}
348342
catch (Throwable ex) {
349343
throw handleRunFailure(context, ex, null);
350344
}
@@ -790,6 +784,9 @@ private <R extends Runner> void callRunner(Class<R> type, Runner runner, Throwin
790784

791785
private RuntimeException handleRunFailure(ConfigurableApplicationContext context, Throwable exception,
792786
SpringApplicationRunListeners listeners) {
787+
if (exception instanceof AbandonedRunException abandonedRunException) {
788+
return abandonedRunException;
789+
}
793790
try {
794791
try {
795792
handleExitCode(context, exception);
@@ -808,10 +805,8 @@ private RuntimeException handleRunFailure(ConfigurableApplicationContext context
808805
catch (Exception ex) {
809806
logger.warn("Unable to close ApplicationContext", ex);
810807
}
811-
if (exception instanceof RuntimeException runtimeException) {
812-
return runtimeException;
813-
}
814-
return new IllegalStateException(exception);
808+
return (exception instanceof RuntimeException runtimeException) ? runtimeException
809+
: new IllegalStateException(exception);
815810
}
816811

817812
private Collection<SpringBootExceptionReporter> getExceptionReporters(ConfigurableApplicationContext context) {

0 commit comments

Comments
 (0)