From 4c1bb38878139d3477cad6336dea001a89a3de3b Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 22 Jan 2016 15:21:00 +0000 Subject: [PATCH] Fix broken locking in Restarter.initialize Closes gh-4955 --- .../boot/devtools/restart/Restarter.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java index e59df1c4d9..70d179002f 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java @@ -525,12 +525,16 @@ public class Restarter { public static void initialize(String[] args, boolean forceReferenceCleanup, RestartInitializer initializer, boolean restartOnInitialize, RestartListener... listeners) { - if (instance == null) { - synchronized (Restarter.class) { - instance = new Restarter(Thread.currentThread(), args, + Restarter localInstance = null; + synchronized (Restarter.class) { + if (instance == null) { + localInstance = new Restarter(Thread.currentThread(), args, forceReferenceCleanup, initializer, listeners); + instance = localInstance; } - instance.initialize(restartOnInitialize); + } + if (localInstance != null) { + localInstance.initialize(restartOnInitialize); } }