From 85cfa4798c65a807d22ef3ebd60381b9efd310e1 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 14 Dec 2023 20:16:23 +0000 Subject: [PATCH] Close jar to allow it to be cleaned up after test execution See gh-38766 --- .../web/servlet/server/StaticResourceJarsTests.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/StaticResourceJarsTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/StaticResourceJarsTests.java index 074582b9af22..a0bb6a4ae835 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/StaticResourceJarsTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/StaticResourceJarsTests.java @@ -96,9 +96,14 @@ void doesNotCloseJarFromCachedConnection() throws Exception { File jarFile = createResourcesJar("test-resources.jar"); TrackedURLStreamHandler handler = new TrackedURLStreamHandler(true); URL url = new URL("jar", null, 0, jarFile.toURI().toURL().toString() + "!/", handler); - new StaticResourceJars().getUrlsFrom(url); - assertThatNoException() - .isThrownBy(() -> ((JarURLConnection) handler.getConnection()).getJarFile().getComment()); + try { + new StaticResourceJars().getUrlsFrom(url); + assertThatNoException() + .isThrownBy(() -> ((JarURLConnection) handler.getConnection()).getJarFile().getComment()); + } + finally { + ((JarURLConnection) handler.getConnection()).getJarFile().close(); + } } @Test