Skip to content

Commit a95a7e3

Browse files
committed
Allow restart to be enabled when CL not named AppClassLoader
Previously, the restart initializer that enables restart when -Dspring.devtools.restart.enabled=true is set had no effect when the ClassLoader's name did not contain AppClassLoader. This commit updates RestartApplicationListener to use the correct RestartInitializer when the system property has forcibly enabled restart. When restart is enabled a SilentExitException is thrown and it should be caught and handled by the SilentExitExceptionHandler. When the application is invoked via one of the loader's LauncherClasses reflection is used and this exception becomes wrapped in an InvocationTargetEception. Previously, this wrapping prevented SilentExitExceptionHandler from handling the exception. This commit updates the handler to look for an InvocationTargetException with a SilentExitException target in addition to continuing to look for a SilentExitException directly. Fixes gh-24797
1 parent 26f143b commit a95a7e3

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/RestartApplicationListener.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -83,12 +83,11 @@ protected boolean isDevelopmentClassLoader(ClassLoader classLoader) {
8383
}
8484
if (restartInitializer != null) {
8585
String[] args = event.getArgs();
86-
DefaultRestartInitializer initializer = new DefaultRestartInitializer();
8786
boolean restartOnInitialize = !AgentReloader.isActive();
8887
if (!restartOnInitialize) {
8988
logger.info("Restart disabled due to an agent-based reloader being active");
9089
}
91-
Restarter.initialize(args, false, initializer, restartOnInitialize);
90+
Restarter.initialize(args, false, restartInitializer, restartOnInitialize);
9291
}
9392
else {
9493
logger.info(LogMessage.format("Restart disabled due to System property '%s' being set to false",

spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/SilentExitExceptionHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.boot.devtools.restart;
1818

1919
import java.lang.Thread.UncaughtExceptionHandler;
20+
import java.lang.reflect.InvocationTargetException;
2021
import java.util.Arrays;
2122

2223
/**
@@ -35,7 +36,8 @@ class SilentExitExceptionHandler implements UncaughtExceptionHandler {
3536

3637
@Override
3738
public void uncaughtException(Thread thread, Throwable exception) {
38-
if (exception instanceof SilentExitException) {
39+
if (exception instanceof SilentExitException || (exception instanceof InvocationTargetException
40+
&& ((InvocationTargetException) exception).getTargetException() instanceof SilentExitException)) {
3941
if (isJvmExiting(thread)) {
4042
preventNonZeroExitCode();
4143
}

0 commit comments

Comments
 (0)