Skip to content

Commit

Permalink
Defensively call Resource.getFile() for fallback resolution
Browse files Browse the repository at this point in the history
Closes gh-31216
  • Loading branch information
jhoeller committed Sep 13, 2023
1 parent 4ca7025 commit 966b0a9
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.core.io.support;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.lang.module.ModuleFinder;
Expand Down Expand Up @@ -786,10 +787,26 @@ protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource
// Fallback via Resource.getFile() below
}
}

if (rootPath == null) {
// Resource.getFile() resolution as a fallback -
// for custom URI formats and custom Resource implementations
rootPath = Path.of(rootDirResource.getFile().getAbsolutePath());
try {
rootPath = Path.of(rootDirResource.getFile().getAbsolutePath());
}
catch (FileNotFoundException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Cannot search for matching files underneath " + rootDirResource +
" in the file system: " + ex.getMessage());
}
return result;
}
catch (Exception ex) {
if (logger.isInfoEnabled()) {
logger.info("Failed to resolve " + rootDirResource + " in the file system: " + ex);
}
return result;
}
}

if (!Files.exists(rootPath)) {
Expand Down

0 comments on commit 966b0a9

Please sign in to comment.