From 2a12f5ea864c9ec44791492c84cc1b80165e554c Mon Sep 17 00:00:00 2001 From: "David M. Lloyd" Date: Tue, 29 Oct 2024 12:50:14 -0500 Subject: [PATCH] Do not return a resource for non-existent filesystem files --- .../io/smallrye/common/resource/PathResourceLoader.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/resource/src/main/java/io/smallrye/common/resource/PathResourceLoader.java b/resource/src/main/java/io/smallrye/common/resource/PathResourceLoader.java index 55201ae..ad213e6 100644 --- a/resource/src/main/java/io/smallrye/common/resource/PathResourceLoader.java +++ b/resource/src/main/java/io/smallrye/common/resource/PathResourceLoader.java @@ -5,6 +5,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.nio.file.FileSystem; +import java.nio.file.Files; import java.nio.file.Path; import io.smallrye.common.constraint.Assert; @@ -41,7 +42,11 @@ public PathResourceLoader(final FileSystem fs) { public Resource findResource(final String path) { String canon = ResourceUtils.canonicalizeRelativePath(path); - return new PathResource(canon, base.resolve(canon)); + Path filePath = base.resolve(canon); + if (!Files.exists(filePath)) { + return null; + } + return new PathResource(canon, filePath); } public URL baseUrl() {