Skip to content

Commit 937dbff

Browse files
committed
Merge branch '3.3.x'
Closes spring-projectsgh-42108
2 parents 41afc6a + 9f38f2b commit 937dbff

File tree

2 files changed

+22
-4
lines changed
  • spring-boot-project/spring-boot-devtools/src

2 files changed

+22
-4
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,12 @@ private LeakSafeThread getLeakSafeThread() {
440440
}
441441

442442
public Object getOrAddAttribute(String name, final ObjectFactory<?> objectFactory) {
443-
return this.attributes.computeIfAbsent(name, (ignore) -> objectFactory.getObject());
443+
Object value = this.attributes.get(name);
444+
if (value == null) {
445+
value = objectFactory.getObject();
446+
this.attributes.put(name, value);
447+
}
448+
return value;
444449
}
445450

446451
public Object removeAttribute(String name) {

spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestarterTests.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 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.
@@ -145,15 +145,28 @@ void addClassLoaderFiles() {
145145
}
146146

147147
@Test
148-
@SuppressWarnings("rawtypes")
149148
void getOrAddAttributeWithExistingAttribute() {
150149
Restarter.getInstance().getOrAddAttribute("x", () -> "abc");
151-
ObjectFactory objectFactory = mock(ObjectFactory.class);
150+
ObjectFactory<?> objectFactory = mock(ObjectFactory.class);
152151
Object attribute = Restarter.getInstance().getOrAddAttribute("x", objectFactory);
153152
assertThat(attribute).isEqualTo("abc");
154153
then(objectFactory).shouldHaveNoInteractions();
155154
}
156155

156+
@Test
157+
void getOrAddAttributeWithRecursion() {
158+
Restarter restarter = Restarter.getInstance();
159+
Object added = restarter.getOrAddAttribute("postgresContainer", () -> {
160+
restarter.getOrAddAttribute("rabbitContainer", () -> "def");
161+
return "abc";
162+
});
163+
ObjectFactory<?> objectFactory = mock(ObjectFactory.class);
164+
assertThat(added).isEqualTo("abc");
165+
assertThat(restarter.getOrAddAttribute("postgresContainer", objectFactory)).isEqualTo("abc");
166+
assertThat(restarter.getOrAddAttribute("rabbitContainer", objectFactory)).isEqualTo("def");
167+
then(objectFactory).shouldHaveNoInteractions();
168+
}
169+
157170
@Test
158171
void getThreadFactory() throws Exception {
159172
final ClassLoader parentLoader = Thread.currentThread().getContextClassLoader();

0 commit comments

Comments
 (0)