You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Dev tools causes misconfigured command-line application to exit with 0Β #28541
When SpringApplication handles the failure it invokes SpringBootExceptionHandler.registerLoggedException for UnsatisfiedDependencyException
The last thing SpringApplication does is ReflectionUtils.rethrowRuntimeException(exception); SpringApplication.java
This causes the exception seen in RestartLauncher to be java.lang.reflect.InvocationTargetException containing target UnsatisfiedDependencyException
Finally, SpringBootExceptionHandler has a registered Exception UnsatisfiedDependencyException .. does not have InvocationTargetException as a registed exception and thus the exit code is 0
Ideally, in this case it should investigate the target of the exception and match it
@cdmatta@wilkinsona
When relying on developmentOnly'org.springframework.boot:spring-boot-devtools', the SpringBoot project will schedule the org.springframework.boot.devtools.restart.RestartLauncher#run() function in devtools when it starts, and the abnormal status code 0 is returned by the abnormal status of devtools,
I guess this problem should be related to the operating principle of spring-boot-devtools.
If this is the intended behavior then I think spring-boot-devtools needs to inform the user that it's changed the exit code! Otherwise this is very non-obvious. Took me ages to track down the culprit.
It looks like a bug to me. preventNonZeroExitCode() should only come into play if the JVM is exiting due to Dev Tools' own SilentExitException. For any other failure the intent is that the exit code should be unchanged. From what @cdmatta has described above, it's an UnsatisfiedDependencyException so the code that's specific to SilentExitException shouldn't be involved.
I've been investigating this and traced the root cause to Restarter.immediateRestart(). When the application fails to start on the restartedMain thread, the error from start(FailureHandler.NONE) is silently discarded - FailureHandler.NONE returns ABORT, start() returns normally, and then SilentExitExceptionHandler.exitCurrentThread() always forces exit code 0.
I have a fix ready that modifies immediateRestart() to detect the application failure and propagate the appropriate exit code (walking the exception cause chain for ExitCodeGenerator implementations).
I notice #26894 describes a related problem with the same restart lifecycle. Before submitting a PR, I wanted to check β is the team open to a targeted fix for the exit code case, or would you prefer a broader approach that addresses both issues together?
@prasanna164-code Thanks for checking. Looking at #26894 we might already have some code to fix this but we haven't yet reviewed it. I'll flag this issue for discussion to see if we want to resurrect the code we have or accept a pull-request.
Activity
msmerc commentedon Nov 5, 2021
Here's my full maven config:
cdmatta commentedon Nov 5, 2021
The app runs within a RestartLauncher due to devtools
https://github.com/spring-projects/spring-boot/blob/v2.5.6/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/RestartLauncher.java#L46-L53
When SpringApplication handles the failure it invokes SpringBootExceptionHandler.registerLoggedException for UnsatisfiedDependencyException
The last thing SpringApplication does is
ReflectionUtils.rethrowRuntimeException(exception);SpringApplication.java
This causes the exception seen in RestartLauncher to be java.lang.reflect.InvocationTargetException containing target UnsatisfiedDependencyException
Finally, SpringBootExceptionHandler has a registered Exception
UnsatisfiedDependencyException.. does not have InvocationTargetException as a registed exception and thus the exit code is 0Ideally, in this case it should investigate the target of the exception and match it
wilkinsona commentedon Nov 15, 2021
#26894 is in a similar area.
CangYa2021 commentedon Nov 27, 2021
@cdmatta @wilkinsona
When relying on developmentOnly'org.springframework.boot:spring-boot-devtools', the SpringBoot project will schedule the org.springframework.boot.devtools.restart.RestartLauncher#run() function in devtools when it starts, and the abnormal status code 0 is returned by the abnormal status of devtools,
I guess this problem should be related to the operating principle of spring-boot-devtools.
CangYa2021 commentedon Nov 27, 2021
@msmerc @cdmatta


You can debug at the following methods.
@wilkinsona I think this situation is not a bug, isn't it ?
msmerc commentedon Nov 29, 2021
If this is the intended behavior then I think spring-boot-devtools needs to inform the user that it's changed the exit code! Otherwise this is very non-obvious. Took me ages to track down the culprit.
wilkinsona commentedon Nov 29, 2021
It looks like a bug to me.
preventNonZeroExitCode()should only come into play if the JVM is exiting due to Dev Tools' ownSilentExitException. For any other failure the intent is that the exit code should be unchanged. From what @cdmatta has described above, it's anUnsatisfiedDependencyExceptionso the code that's specific toSilentExitExceptionshouldn't be involved.22 remaining items
prasanna164-code commentedon Mar 5, 2026
I've been investigating this and traced the root cause to
Restarter.immediateRestart(). When the application fails to start on therestartedMainthread, the error fromstart(FailureHandler.NONE)is silently discarded -FailureHandler.NONEreturnsABORT,start()returns normally, and thenSilentExitExceptionHandler.exitCurrentThread()always forces exit code 0.I have a fix ready that modifies
immediateRestart()to detect the application failure and propagate the appropriate exit code (walking the exception cause chain forExitCodeGeneratorimplementations).I notice #26894 describes a related problem with the same restart lifecycle. Before submitting a PR, I wanted to check β is the team open to a targeted fix for the exit code case, or would you prefer a broader approach that addresses both issues together?
philwebb commentedon Mar 11, 2026
@prasanna164-code Thanks for checking. Looking at #26894 we might already have some code to fix this but we haven't yet reviewed it. I'll flag this issue for discussion to see if we want to resurrect the code we have or accept a pull-request.
Propagate error on restart abort instead of silently returning