From f31eb2dcf9f03148907ea49c209144753c96573a Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sun, 25 Sep 2022 19:16:27 +0200 Subject: [PATCH] Skip scanning the module path when running in a native image Prior to this commit, the following exception was thrown when using the PathMatchingResourcePatternResolver to scan for class path resources using the `classpath*:` prefix within a native image. com.oracle.svm.core.jdk.UnsupportedFeatureError: JRT file system is disabled com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:89) jdk.internal.module.SystemModuleFinders$SystemImage.reader(SystemModuleFinders.java:139) jdk.internal.module.SystemModuleFinders$ModuleContentSpliterator.(SystemModuleFinders.java:527) jdk.internal.module.SystemModuleFinders$SystemModuleReader.list(SystemModuleFinders.java:502) org.springframework.core.io.support.PathMatchingResourcePatternResolver.lambda$findAllModulePathResources$6(PathMatchingResourcePatternResolver.java:819) This commit addresses this by not attempting to scan the module path when running in a GraalVM native image. Closes gh-29183 --- .../io/support/PathMatchingResourcePatternResolver.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java index 47e14aba1d8..490c5abc5ed 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java @@ -892,6 +892,12 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol */ protected Set findAllModulePathResources(String locationPattern) throws IOException { Set result = new LinkedHashSet<>(16); + + // Skip scanning the module path when running in a native image. + if (NativeDetector.inNativeImage()) { + return result; + } + String resourcePattern = stripLeadingSlash(locationPattern); Predicate resourcePatternMatches = (getPathMatcher().isPattern(resourcePattern) ? path -> getPathMatcher().match(resourcePattern, path) :