Browse Source

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.<init>(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
pull/29202/head
Sam Brannen 3 years ago
parent
commit
f31eb2dcf9
  1. 6
      spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java

6
spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java

@ -892,6 +892,12 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol @@ -892,6 +892,12 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
*/
protected Set<Resource> findAllModulePathResources(String locationPattern) throws IOException {
Set<Resource> 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<String> resourcePatternMatches = (getPathMatcher().isPattern(resourcePattern) ?
path -> getPathMatcher().match(resourcePattern, path) :

Loading…
Cancel
Save