From 31d98bfd959620fe32717de6eab6be2535f7c9cf Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Tue, 4 Oct 2022 16:13:46 +0200 Subject: [PATCH] Ensure PathMatchingResourcePatternResolverTests run in native image See inline comments in commit for details. See gh-29243 --- ...hMatchingResourcePatternResolverTests.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java b/spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java index b091476f6107..8866436504ff 100644 --- a/spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java @@ -26,6 +26,7 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; import org.springframework.util.StringUtils; @@ -200,15 +201,15 @@ private void assertExactSubPaths(String pattern, String pathPrefix, String... su } private String getPath(Resource resource) { - try { - // Tests fail if we use getURL(). They would also fail on Mac OS when using getURI() - // if the resource paths are not Unicode normalized. - // See: https://github.com/spring-projects/spring-framework/issues/29243 - return resource.getFile().getPath(); - } - catch (IOException ex) { - throw new UncheckedIOException(ex); - } + // Tests fail if we use resouce.getURL().getPath(). They would also fail on Mac OS when + // using resouce.getURI().getPath() if the resource paths are not Unicode normalized. + // + // On the JVM, all tests should pass when using resouce.getFile().getPath(); however, + // we use FileSystemResource#getPath since this test class is sometimes run within a + // GraalVM native image which cannot support Path#toFile. + // + // See: https://github.com/spring-projects/spring-framework/issues/29243 + return ((FileSystemResource) resource).getPath(); } }