Skip to content

Commit 24d729e

Browse files
committed
Close ClassLoader so jar it references can be deleted on Windows
Polishes 952ac7b
1 parent c43ae0b commit 24d729e

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.io.FileOutputStream;
2121
import java.io.IOException;
2222
import java.io.InputStream;
23-
import java.net.MalformedURLException;
2423
import java.net.URL;
2524
import java.net.URLClassLoader;
2625
import java.nio.charset.StandardCharsets;
@@ -219,17 +218,18 @@ void proxyOnClassFromSystemClassLoaderDoesNotYieldWarning() {
219218
}
220219

221220
@Test
222-
void packagePrivateClassLoadedByParentClassLoaderCanBeProxied() throws MalformedURLException {
223-
new ApplicationContextRunner()
224-
.withClassLoader(new RestartClassLoader(ExampleTransactional.class.getClassLoader(),
225-
new URL[] { this.sampleJarFile.toURI().toURL() }, this.updatedFiles))
226-
.withUserConfiguration(ProxyConfiguration.class).run((context) -> {
227-
assertThat(context).hasNotFailed();
228-
ExampleTransactional transactional = context.getBean(ExampleTransactional.class);
229-
assertThat(AopUtils.isCglibProxy(transactional)).isTrue();
230-
assertThat(transactional.getClass().getClassLoader())
231-
.isEqualTo(ExampleTransactional.class.getClassLoader());
232-
});
221+
void packagePrivateClassLoadedByParentClassLoaderCanBeProxied() throws IOException {
222+
try (RestartClassLoader restartClassLoader = new RestartClassLoader(ExampleTransactional.class.getClassLoader(),
223+
new URL[] { this.sampleJarFile.toURI().toURL() }, this.updatedFiles)) {
224+
new ApplicationContextRunner().withClassLoader(restartClassLoader)
225+
.withUserConfiguration(ProxyConfiguration.class).run((context) -> {
226+
assertThat(context).hasNotFailed();
227+
ExampleTransactional transactional = context.getBean(ExampleTransactional.class);
228+
assertThat(AopUtils.isCglibProxy(transactional)).isTrue();
229+
assertThat(transactional.getClass().getClassLoader())
230+
.isEqualTo(ExampleTransactional.class.getClassLoader());
231+
});
232+
}
233233
}
234234

235235
private String readString(InputStream in) throws IOException {

0 commit comments

Comments
 (0)