Skip to content

Commit dfc0ec5

Browse files
vaadin-botArtur-mcollovati
authored
fix: move thread start out of DevServerWatchDog constructor (#23898) (#23919)
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 eb6d0a9 commit dfc0ec5

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
@@ -197,7 +197,9 @@ void doStartDevModeServer() throws ExecutionFailedException {
197197
long start = System.nanoTime();
198198
getLogger().info("Starting " + getServerName());
199199

200-
watchDog.set(new DevServerWatchDog());
200+
DevServerWatchDog newWatchDog = new DevServerWatchDog();
201+
newWatchDog.start();
202+
watchDog.set(newWatchDog);
201203

202204
// Look for a free port
203205
port = 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
@@ -79,7 +79,9 @@ private Logger getLogger() {
7979

8080
DevServerWatchDog() {
8181
watchDogServer = new WatchDogServer();
82+
}
8283

84+
void start() {
8385
Thread serverThread = new Thread(watchDogServer);
8486
serverThread.setDaemon(true);
8587
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
@@ -190,6 +190,7 @@ private void assertOnDevProcessEnvironment(
190190
Class<? extends InetAddress> loopbackAddressType,
191191
Consumer<Map<String, String>> op) {
192192
final DevServerWatchDog watchDog = new DevServerWatchDog();
193+
watchDog.start();
193194
final InetAddress loopbackAddress = findLocalhostAddress(
194195
loopbackAddressType);
195196
try {

0 commit comments

Comments
 (0)