gnodet commented on code in PR #24475:
URL: https://github.com/apache/camel/pull/24475#discussion_r3533793764
##########
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:
_Claude Code on behalf of gnodet_
Good catch — fixed in 45396a7. The classloader is now null-checked before
calling `getResourceAsStream()`, so if `Theme.class.getClassLoader()` returns
null (bootstrap-loaded class), we fall through cleanly to the TCCL fallback
instead of throwing an NPE. The javadoc was also updated to document this path.
--
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]