Skip to content

Commit 1c544a0

Browse files
vaadin-botArtur-mcollovati
authored
fix: move thread start out of DevServerWatchDog constructor (#23898) (#23915)
Starting a thread in a constructor can expose a partially constructed object. Extract the thread start into a separate start() method that callers invoke after construction completes. Co-authored-by: Artur Signell <artur@vaadin.com> Co-authored-by: Marco Collovati <marco@vaadin.com>
1 parent e1163e9 commit 1c544a0

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

vaadin-dev-server/src/main/java/com/vaadin/base/devserver/AbstractDevServerRunner.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ void doStartDevModeServer() throws ExecutionFailedException {
204204
long start = System.nanoTime();
205205
getLogger().info("Starting " + getServerName());
206206

207-
watchDog.set(new DevServerWatchDog());
207+
DevServerWatchDog newWatchDog = new DevServerWatchDog();
208+
newWatchDog.start();
209+
watchDog.set(newWatchDog);
208210

209211
// Look for a free port
210212
port = NetworkUtil.getFreePort();

vaadin-dev-server/src/main/java/com/vaadin/base/devserver/DevServerWatchDog.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ private Logger getLogger() {
8686

8787
DevServerWatchDog() {
8888
watchDogServer = new WatchDogServer();
89+
}
8990

91+
void start() {
9092
Thread serverThread = new Thread(watchDogServer);
9193
serverThread.setDaemon(true);
9294
serverThread.start();

vaadin-dev-server/src/test/java/com/vaadin/base/devserver/AbstractDevServerRunnerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ private void assertOnDevProcessEnvironment(
183183
Class<? extends InetAddress> loopbackAddressType,
184184
Consumer<Map<String, String>> op) {
185185
final DevServerWatchDog watchDog = new DevServerWatchDog();
186+
watchDog.start();
186187
final InetAddress loopbackAddress = findLocalhostAddress(
187188
loopbackAddressType);
188189
try {

0 commit comments

Comments
 (0)