From 9dc5aa2863f598a15d3dfa116f4b89249daba7e7 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 23 Apr 2026 11:20:34 +0100 Subject: [PATCH] Polish See gh-50170 --- .../springframework/boot/system/ApplicationTemp.java | 2 ++ .../boot/system/ApplicationTempTests.java | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system/ApplicationTemp.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system/ApplicationTemp.java index b74d1802e42..1f426131cf8 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system/ApplicationTemp.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system/ApplicationTemp.java @@ -148,6 +148,8 @@ public class ApplicationTemp { assertDirectoryOwnership(attributes.owner(), path); } else { + Assert.state(Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS), + () -> "'" + path + "' already exists but it is not a directory"); try { assertDirectoryOwnership(Files.getOwner(path, LinkOption.NOFOLLOW_LINKS), path); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/system/ApplicationTempTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/system/ApplicationTempTests.java index 7487cd94f03..3d74a0408b4 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/system/ApplicationTempTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/system/ApplicationTempTests.java @@ -27,8 +27,11 @@ import java.util.EnumSet; import java.util.Set; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; import org.springframework.util.FileSystemUtils; @@ -88,6 +91,7 @@ class ApplicationTempTests { } @Test + @DisabledOnOs(OS.WINDOWS) void whenDirectoryExistsWithWrongPermissionsGetDirThrows() throws IOException { ApplicationTemp temp = new ApplicationTemp(); Path path = temp.getDir().toPath(); @@ -104,7 +108,12 @@ class ApplicationTempTests { Path path = temp.getDir().toPath(); FileSystemUtils.deleteRecursively(path); Path linkTarget = Files.createTempDirectory("application-test-tests"); - Files.createSymbolicLink(path, linkTarget); + try { + Files.createSymbolicLink(path, linkTarget); + } + catch (Exception ex) { + Assumptions.abort("Symlink creation not supported"); + } assertThatIllegalStateException().isThrownBy(new ApplicationTemp()::getDir) .withMessageContaining("already exists but it is not a directory"); FileSystemUtils.deleteRecursively(path);