@@ -2417,23 +2417,20 @@ public static String getRequestURI(HttpServletRequest request) {
24172417 }
24182418
24192419 /**
2420- * Finds a resource with a given name. This method returns null if no
2421- * resource with this name is found.
2420+ * Finds a resource with a given name. This method returns {@code null} if no resource with this name is found.
24222421 * <p>
2423- * This method uses the current <tt>Thread</tt> context <tt>ClassLoader</tt> to find
2424- * the resource. If the resource is not found the class loader of the given
2425- * class is then used to find the resource.
2426- *
2422+ * This method uses the current <tt>Thread</tt> context <tt>ClassLoader</tt> to find the resource.
2423+ * If the resource is not found the class loader of the given class is then used to find the resource.
2424+
24272425 * @param name the name of the resource
2428- * @param aClass the class lookup the resource against, if the resource is
2429- * not found using the current <tt>Thread</tt> context <tt>ClassLoader</tt>.
2430- * @return the input stream of the resource if found or null otherwise
2426+ * @param aClass the class lookup the resource against, if the resource is not found using the current <tt>Thread</tt> context <tt>ClassLoader</tt>.
2427+ * @return the input stream of the resource if found or {@code null} otherwise
24312428 */
24322429 @ Nullable
24332430 public static InputStream getResourceAsStream (@ NonNull String name , @ NonNull Class <?> aClass ) {
24342431 if (name .startsWith ("/" )){
24352432 log .warn ("getResourceAsStream: name must be relative, but: {} @ {}" , name , aClass );
2436- name = name .substring (1 );
2433+ name = name .substring (1 );// ~ /WEB-INF/foo ~ WEB-INF/foo
24372434 }
24382435 val classLoader = Thread .currentThread ().getContextClassLoader ();
24392436 if (classLoader != null ){
@@ -2451,15 +2448,13 @@ public static InputStream getResourceAsStream (@NonNull String name, @NonNull Cl
24512448 InputStream is = aClass .getResourceAsStream (name );
24522449 if (is != null ){ return is ; }
24532450
2454- is = ClickUtils .class .getResourceAsStream (name );
2451+ is = ClickUtils .class .getResourceAsStream (name );// fallback to lib class loader
24552452 if (is != null ){ return is ; }
24562453
2457- if (name .startsWith ("WEB-INF/" )){// hack old Click to work with Boot
2458- name = name .substring (8 );// ^ cut
2459- is = getResourceAsStream (name , aClass );
2460- if (is != null ){ return is ; }
2461-
2462- return getResourceAsStream ("META-INF/resources/" +name , aClass );
2454+ if (name .startsWith ("WEB-INF/" )){// hack old Click to work with Boot ?WEB-INF/classes
2455+ return getResourceAsStream (name .substring (8 ), aClass );// no more WEB-INF ⇒ resource in /resources?
2456+ } else if (!name .startsWith ("META-INF/resources/" )){// try in pseudo "/WEB-INF/" ~ replace "/WEB-INF/" with real servlet-container location of resources
2457+ return getResourceAsStream ("META-INF/resources/" + name , aClass );
24632458 }
24642459 return null ;// not found anywhere
24652460 }
@@ -2468,9 +2463,9 @@ public static InputStream getResourceAsStream (@NonNull String name, @NonNull Cl
24682463 Get best ClassLoader.
24692464 Get {@link Thread#getContextClassLoader Thread.currentThread().getContextClassLoader()}.
24702465 If null then fallback to {@link Class#getClassLoader() Throw.class::getClassLoader}*/
2471- public static ClassLoader classLoader (){
2466+ public static ClassLoader classLoader () {
24722467 var cl = Thread .currentThread ().getContextClassLoader ();
2473- return cl != null ? cl // <^ ~ Objects.requireNonNullElseGet
2468+ return cl != null ? cl // <^ ~ Objects.requireNonNullElseGet
24742469 : ClickUtils .class .getClassLoader ();
24752470 }
24762471
0 commit comments