Skip to content

Commit 31d98bf

Browse files
committed
Ensure PathMatchingResourcePatternResolverTests run in native image
See inline comments in commit for details. See gh-29243
1 parent dd814b6 commit 31d98bf

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.junit.jupiter.api.Nested;
2727
import org.junit.jupiter.api.Test;
2828

29+
import org.springframework.core.io.FileSystemResource;
2930
import org.springframework.core.io.Resource;
3031
import org.springframework.util.StringUtils;
3132

@@ -200,15 +201,15 @@ private void assertExactSubPaths(String pattern, String pathPrefix, String... su
200201
}
201202

202203
private String getPath(Resource resource) {
203-
try {
204-
// Tests fail if we use getURL(). They would also fail on Mac OS when using getURI()
205-
// if the resource paths are not Unicode normalized.
206-
// See: https://github.com/spring-projects/spring-framework/issues/29243
207-
return resource.getFile().getPath();
208-
}
209-
catch (IOException ex) {
210-
throw new UncheckedIOException(ex);
211-
}
204+
// Tests fail if we use resouce.getURL().getPath(). They would also fail on Mac OS when
205+
// using resouce.getURI().getPath() if the resource paths are not Unicode normalized.
206+
//
207+
// On the JVM, all tests should pass when using resouce.getFile().getPath(); however,
208+
// we use FileSystemResource#getPath since this test class is sometimes run within a
209+
// GraalVM native image which cannot support Path#toFile.
210+
//
211+
// See: https://github.com/spring-projects/spring-framework/issues/29243
212+
return ((FileSystemResource) resource).getPath();
212213
}
213214

214215
}

0 commit comments

Comments
 (0)