From 2dc3660a3260726d543f4f70b634c1283e11f308 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 21 Jan 2016 09:57:02 +0000 Subject: [PATCH] Align launcher exception handling with direct invocation of main method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, if an application’s main method threw an exception, MainMethodRunner would catch the exception and call System.exit(1). This meant that the JVM would exit, irrespective of whether or not any non-daemon threads were running. In contrast, when an application’s main method was invoked directly (in an IDE, for example) the JVM would not exit if one or more non-daemon threads were running. This is standard JVM behaviour that we should be consistent with in the launcher. This commit updates MainMethodRunner to wrap any exception thrown by an application’s main method in a RuntimeException and rethrow it. This alllows the JVM to handle the exception and use its normal rules for deciding whether or not it should exit. Closes gh-4984 --- .../org/springframework/boot/loader/MainMethodRunner.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/MainMethodRunner.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/MainMethodRunner.java index 8633ed6d6a..91cfbeee8e 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/MainMethodRunner.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/MainMethodRunner.java @@ -59,10 +59,7 @@ public class MainMethodRunner implements Runnable { if (handler != null) { handler.uncaughtException(Thread.currentThread(), ex); } - else { - ex.printStackTrace(); - } - System.exit(1); + throw new RuntimeException(ex); } }