Skip to content

Dev tools causes misconfigured command-line application to exit with 0Β #28541

Open

Description

@msmerc

I have a really simple spring application that's misconfigured:

@SpringBootApplication()
public class SimpleApplication implements CommandLineRunner {
    public static void main(String[] args) {
        var ctx = SpringApplication.run(SimpleApplication.class, args);
        System.exit(SpringApplication.exit(ctx));
    }

    public static class MyObject {}
    
    //Oops - No bean provided!!!
    @Autowired MyObject myObject;

    @Override public void run(String... args) { }
}

I get the following error (in intellij):

...
Consider defining a bean of type 'test.app.SimpleApplication$MyObject' in your configuration.


Process finished with exit code 1

Which is what I'd expect.

If I add the spring-boot-devtools dependency in maven:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>

Then I get the following:

...
Consider defining a bean of type 'test.app.SimpleApplication$MyObject' in your configuration.


Process finished with exit code 0

It seems that adding this package causes spring boot to have the wrong return codes.

Activity

  1. msmerc commented on Nov 5, 2021

    @msmerc
    Author

    Here's my full maven config:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>org.example</groupId>
        <artifactId>springboot-test</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <properties>
            <maven.compiler.source>13</maven.compiler.source>
            <maven.compiler.target>13</maven.compiler.target>
        </properties>
    
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-dependencies</artifactId>
                    <version>2.5.5</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
        <dependencies>
            <!-- This dependency causes the issue -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
        </dependencies>
    </project>
  2. cdmatta commented on Nov 5, 2021

    @cdmatta
    1. 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

    2. When SpringApplication handles the failure it invokes SpringBootExceptionHandler.registerLoggedException for UnsatisfiedDependencyException

    3. The last thing SpringApplication does is ReflectionUtils.rethrowRuntimeException(exception);
      SpringApplication.java

    4. This causes the exception seen in RestartLauncher to be java.lang.reflect.InvocationTargetException containing target UnsatisfiedDependencyException

    5. Finally, SpringBootExceptionHandler has a registered Exception UnsatisfiedDependencyException .. does not have InvocationTargetException as a registed exception and thus the exit code is 0

    RegisteredExceptionVsActual

    Ideally, in this case it should investigate the target of the exception and match it

  3. added this to the 2.4.x milestone on Nov 10, 2021
  4. removed their assignment
    on Nov 10, 2021
  5. modified the milestones: 2.4.x, 2.5.x on Nov 15, 2021
  6. wilkinsona commented on Nov 15, 2021

    @wilkinsona
    Member

    #26894 is in a similar area.

  7. CangYa2021 commented on Nov 27, 2021

    @CangYa2021

    @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.

  8. CangYa2021 commented on Nov 27, 2021

    @CangYa2021

    @msmerc @cdmatta
    You can debug at the following methods.
    image
    image

    @wilkinsona I think this situation is not a bug, isn't it ?

  9. msmerc commented on Nov 29, 2021

    @msmerc
    Author

    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.

  10. wilkinsona commented on Nov 29, 2021

    @wilkinsona
    Member

    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.

  11. 22 remaining items

  12. modified the milestones: 3.2.x, 3.3.x on Nov 20, 2024
  13. modified the milestones: 3.3.x, 3.4.x on May 23, 2025
  14. modified the milestones: 3.4.x, 3.5.x on Dec 16, 2025
  15. prasanna164-code commented on Mar 5, 2026

    @prasanna164-code

    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?

  16. philwebb commented on Mar 11, 2026

    @philwebb
    Member

    @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.

  17. added a commit that references this issue on May 19, 2026
    fbaa0d1
  18. modified the milestones: 3.5.x, 4.0.x on Jun 25, 2026
  19. added and removed
    for: team-meetingAn issue we'd like to discuss as a team to make progress
    on Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions