115

Every time I run my Spring Boot project on debug mode in Eclipse IDE (Spring Tool Suite), the thread stops at throw new SilentExitException(); line even without a breakpoint.

Is there some solution to avoid this behavior?

org.springframework.boot.devtools.restart.SilentExitExceptionHandler.exitCurrentThread() (line 53):

public static void exitCurrentThread() {
    throw new SilentExitException();
}

This starts happening after upgrade to 1.3.0 Milestones.

Spring Tool Suite

Version: 3.7.0.RELEASE
Build Id: 201506290649

Platform:

Eclipse Luna SR2 (4.4.2)
Bruno De Freitas Barros
  • 2,199
  • 2
  • 17
  • 16
  • 2
    For IntelliJ users who landed here: Add a condition to the breakpoint in Run | View Breakpoints... | Any Exceptions: `return !(this instanceof org.springframework.boot.devtools.restart.SilentExitExceptionHandler.SilentExitException);` This must be Java even if you develop in another JVM language. – Marco Eckstein May 03 '19 at 14:44

10 Answers10

143

This is unfortunately a know issue with the new spring-boot-devtools module (see https://github.com/spring-projects/spring-boot/issues/3100). We use this trick to kill the main thread so that we can replace it with a re-loadable version. So far I've not found a way to prevent the debug breakpoint from triggering.

For now, you can toggle the "suspend execution on uncaught exceptions" checkbox in Java -> Debug preferences to prevent it from happening.

Phil Webb
  • 8,119
  • 1
  • 37
  • 37
34

Add the property as a VM argument:

-Dspring.devtools.restart.enabled=false

enter image description here

That way you don't have to change your code, as it is the case when using:

System.setProperty("spring.devtools.restart.enabled", "false");
mushipao
  • 376
  • 5
  • 7
xbranko
  • 585
  • 5
  • 12
  • 1
    Out of other options, I used this. Thanks a lot for making my day! – sivakadi Mar 17 '20 at 17:44
  • Thank u for share!!! I used in the main method with: System.setProperty("spring.devtools.restart.enabled", "false"); – Ivan Rodrigues Mar 15 '22 at 21:29
  • This works !! For silent exit without a relevant stacktrace. I also had a mysql-connector-java version issue before this which can also cause a silent exit exception. For that if you are using the 5.1.6 try switching to 5.1.49. – Yash Nasery Sep 22 '22 at 06:34
16

As Eclipse on Debug mode already allows limited hotpatching, I find the reloader to be counterproductive most of the time and so I decided to disable it by:

System.setProperty("spring.devtools.restart.enabled", "false");

Reference: https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html#using-boot-devtools-restart-disable

Since that exception is thrown by the reloader, this also solves this issue. Note that you'll have to use the System.setProperty method instead of setting it in application.properties.

RichN
  • 6,181
  • 3
  • 30
  • 38
5

My workaround:

public static void main(String[] args) {
    try {
        SpringApplication.run(App.class, args);
    } catch (Throwable e) {
        if(e.getClass().getName().contains("SilentExitException")) {
            LOGGER.debug("Spring is restarting the main thread - See spring-boot-devtools");
        } else {
            LOGGER.error("Application crashed!", e);
        }
    }
}

It doesn't matter that we ignore the SilentExitException because the devtools are just restarting the instance with a SilentExitException which isn't very silent. This try block will silence it...

I had to use text matching on the class as the SilentExitException is private in SilentExitExceptionHandler.

It doesn't solve your problem with the breakpoint...

Dan Thomas
  • 357
  • 1
  • 4
  • 13
4

Delete these to Unknown Exceptions & it won't break there: enter image description here

Unfortunately, I haven't found a way for this to be permanent, but it should last till the next time you restart eclipse.

ScrappyDev
  • 2,307
  • 8
  • 40
  • 60
1

I had same issue while running spring boot project. I found TRY CATCH block used in Main method.

Remove the try catch block run the code. that error will not come again. like below:

public static void main(String[] args) {

    SpringApplication.run(TrewAuthApplication.class, args);

}
1

Set this in your application.properties file to true.

spring.devtools.restart.enabled=false

Also go sure that if you use a spring cloud config server, there is no propertie file that enables this.

Tristate
  • 1,498
  • 2
  • 18
  • 38
  • Thi disables live-reload in apps like vaadin when you want to debug... The user just wanted to get rid of this exception stopping him from debugging. Therefore this doesnt help getting rid of the exception, it disables the complete feature. – Arquillian Jan 14 '23 at 20:59
0

Try to run devtools at scope runtime:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
</dependency>
ra1729
  • 27
  • 3
0

My workaround in Kotlin:

@JvmStatic
fun main(args: Array<String>) {
  val app = SpringApplication(Application::class.java)
  try {
    app.run(*args)
  } catch (e: Exception) {
    preventNonNullExitCodeOnSilentExitException(e)
  }
}

private fun preventNonNullExitCodeOnSilentExitException(e: Exception) {
  if (e.toString().contains("SilentExitException")) {
    log.info("Ignoring Silent Exit Exception...")
    e.printStackTrace()
    return
  }
  throw e
}
Jan Cizmar
  • 372
  • 2
  • 11
0

In the meantime this seems fixed when you use Spring Tools Suite latest. BUT when you START your application the exception still occurs and the debugger stops. Just after the first live-/hot-reload it will be ignored by STS. If you take a look at Preferences - Spring, there is a flag for this exception.

Arquillian
  • 125
  • 2
  • 16