From 8f80c93b7548f95fc40581080dbd3aafc6f2d718 Mon Sep 17 00:00:00 2001 From: "David M. Lloyd" Date: Fri, 3 May 2024 08:18:06 -0500 Subject: [PATCH] Fix possible NPE from resource loading Fixes #40438. (cherry picked from commit 97c797ab8783bf200e737f9c0ea5b37f2bc46a35) --- .../io/quarkus/bootstrap/classloading/ClassPathElement.java | 3 ++- .../bootstrap/classloading/PathTreeClassPathElement.java | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/ClassPathElement.java b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/ClassPathElement.java index 99e32e0984df7..2378ecdfafb70 100644 --- a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/ClassPathElement.java +++ b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/ClassPathElement.java @@ -132,6 +132,7 @@ public void close() { }; default List getResources(String name) { - return List.of(getResource(name)); + ClassPathResource resource = getResource(name); + return resource == null ? List.of() : List.of(resource); } } diff --git a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/PathTreeClassPathElement.java b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/PathTreeClassPathElement.java index 6d005f294c424..61bf42a4cb9a5 100644 --- a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/PathTreeClassPathElement.java +++ b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/PathTreeClassPathElement.java @@ -113,7 +113,7 @@ public List getResources(String name) { final String sanitized = sanitize(name); final Set resources = this.resources; if (resources != null && !resources.contains(sanitized)) { - return null; + return List.of(); } List ret = new ArrayList<>(); apply(tree -> { @@ -123,7 +123,7 @@ public List getResources(String name) { } }); - return null; + return List.of(); }); return ret; }