Skip to content

Commit 2dc3660

Browse files
committed
Align launcher exception handling with direct invocation of main method
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
1 parent 9f728b3 commit 2dc3660

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/MainMethodRunner.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ public void run() {
5959
if (handler != null) {
6060
handler.uncaughtException(Thread.currentThread(), ex);
6161
}
62-
else {
63-
ex.printStackTrace();
64-
}
65-
System.exit(1);
62+
throw new RuntimeException(ex);
6663
}
6764
}
6865

0 commit comments

Comments
 (0)