9595import org .springframework .util .ClassUtils ;
9696import org .springframework .util .CollectionUtils ;
9797import org .springframework .util .ObjectUtils ;
98- import org .springframework .util .ReflectionUtils ;
9998import org .springframework .util .StringUtils ;
10099import org .springframework .util .function .ThrowingConsumer ;
101100import org .springframework .util .function .ThrowingSupplier ;
172171 * @author Ethan Rubinson
173172 * @author Chris Bono
174173 * @author Tadaya Tsuyukubo
174+ * @author Lasse Wulff
175175 * @since 1.0.0
176176 * @see #run(Class, String[])
177177 * @see #run(Class[], String[])
@@ -331,11 +331,7 @@ public ConfigurableApplicationContext run(String... args) {
331331 callRunners (context , applicationArguments );
332332 }
333333 catch (Throwable ex ) {
334- if (ex instanceof AbandonedRunException ) {
335- throw ex ;
336- }
337- handleRunFailure (context , ex , listeners );
338- throw new IllegalStateException (ex );
334+ throw handleRunFailure (context , ex , listeners );
339335 }
340336 try {
341337 if (context .isRunning ()) {
@@ -344,11 +340,7 @@ public ConfigurableApplicationContext run(String... args) {
344340 }
345341 }
346342 catch (Throwable ex ) {
347- if (ex instanceof AbandonedRunException ) {
348- throw ex ;
349- }
350- handleRunFailure (context , ex , null );
351- throw new IllegalStateException (ex );
343+ throw handleRunFailure (context , ex , null );
352344 }
353345 return context ;
354346 }
@@ -790,8 +782,11 @@ private <R extends Runner> void callRunner(Class<R> type, Runner runner, Throwin
790782 .accept ((R ) runner );
791783 }
792784
793- private void handleRunFailure (ConfigurableApplicationContext context , Throwable exception ,
785+ private RuntimeException handleRunFailure (ConfigurableApplicationContext context , Throwable exception ,
794786 SpringApplicationRunListeners listeners ) {
787+ if (exception instanceof AbandonedRunException abandonedRunException ) {
788+ return abandonedRunException ;
789+ }
795790 try {
796791 try {
797792 handleExitCode (context , exception );
@@ -810,7 +805,8 @@ private void handleRunFailure(ConfigurableApplicationContext context, Throwable
810805 catch (Exception ex ) {
811806 logger .warn ("Unable to close ApplicationContext" , ex );
812807 }
813- ReflectionUtils .rethrowRuntimeException (exception );
808+ return (exception instanceof RuntimeException runtimeException ) ? runtimeException
809+ : new IllegalStateException (exception );
814810 }
815811
816812 private Collection <SpringBootExceptionReporter > getExceptionReporters (ConfigurableApplicationContext context ) {
0 commit comments