Copilot commented on code in PR #24475:
URL: https://github.com/apache/camel/pull/24475#discussion_r3533770634


##########
dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/Theme.java:
##########
@@ -253,6 +261,28 @@ private static synchronized StyleEngine engine() {
         return engine;
     }
 
+    /**
+     * Reads a CSS resource from the classpath using this class's own 
classloader, which is guaranteed to have access to
+     * project resources regardless of classloader hierarchy.
+     */
+    private static String loadCssResource(String path) throws IOException {
+        InputStream is = 
Theme.class.getClassLoader().getResourceAsStream(path);
+        if (is == null) {
+            // Fallback to the thread context classloader in case the class's 
own classloader
+            // doesn't have visibility (e.g., in OSGi or custom classloader 
setups).
+            ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+            if (tccl != null) {
+                is = tccl.getResourceAsStream(path);
+            }
+        }
+        if (is == null) {
+            throw new IOException("Theme CSS resource not found on classpath: 
" + path);
+        }
+        try (InputStream in = is) {
+            return new String(in.readAllBytes(), StandardCharsets.UTF_8);
+        }
+    }

Review Comment:
   `Theme.class.getClassLoader()` can legally return null (bootstrap-loaded 
classes). In that case this code will throw a NullPointerException before the 
TCCL fallback is attempted. Handle a null classloader explicitly so missing 
resources degrade to the intended IOException/logged fallback instead of an 
unexpected NPE.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to