New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spring-boot-loader: return code is 0 despite UnsupportedClassVersionError #5006
Comments
TL;DR Returning an appropriate exit code is what we want to do, but I don't think that handling Our goal is for |
Here's a possible fix: diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/Launcher.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/Launcher.java
index 3bcd43a..a57787d 100644
--- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/Launcher.java
+++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/Launcher.java
@@ -17,6 +17,7 @@
package org.springframework.boot.loader;
import java.io.File;
+import java.lang.Thread.UncaughtExceptionHandler;
import java.lang.reflect.Constructor;
import java.net.URI;
import java.net.URL;
@@ -103,6 +104,15 @@ public abstract class Launcher {
Thread runnerThread = new Thread(runner);
runnerThread.setContextClassLoader(classLoader);
runnerThread.setName(Thread.currentThread().getName());
+ runnerThread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
+
+ @Override
+ public void uncaughtException(Thread thread, Throwable ex) {
+ ex.printStackTrace();
+ System.exit(1);
+ }
+
+ });
runnerThread.start();
} It has the desired effect of producing a non-zero exit code for an |
We are using spring-boot-loader 1.3.2 in order to build our dropwizard application fat jar. Due to a bad configuration, we ended up building the fat jar with java 8 and try to run it in order to perform some tests with java 7. As expected, launching the application fails with UnsupportedClassVersionError. The issue is that the return code is zero despite the failure.
I think that this is due to MainMethodRunner.run not handling this Error and, as a result, the thread just dies. Do you think it would make sense to try to handle UnsupportedClassVersionError (despite being an Error) in order to be able to return an appropriate exit code?
The text was updated successfully, but these errors were encountered: