-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LNK-3334: Error occurred while evaluating measure: Cannot invoke "java.net.URL.openConnection()" because "url" is null #607
Conversation
Use the main thread's context class loader (rather than the system class loader) to resolve logback-cli.xml from the classpath. Otherwise resolution fails in a Spring Boot `repackage`d fat JAR, because the system class loader doesn't support reaching into nested JARs to find resources.
WalkthroughThe pull request modifies the Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
Java/measureeval/src/main/java/com/lantanagroup/link/measureeval/FileSystemInvocation.java (1)
37-53
: Core fix looks good, but error handling could be improved.The change to use
Thread.currentThread().getContextClassLoader()
correctly addresses the issue of resolvinglogback-cli.xml
from the classpath in a Spring Boot fat JAR. The implementation properly handles the case where the resource is not found.However, consider these improvements to make the error handling more robust:
- Add a fallback configuration when
logback-cli.xml
is not found- Consider logging at ERROR level for configuration failures that might impact application behavior
Here's a suggested improvement:
private static void configureLogging(Bundle bundle) { try { LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); context.reset(); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(context); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL resource = classLoader.getResource("logback-cli.xml"); if (resource == null) { - logger.warn("logback-cli.xml not found in classpath"); - return; + logger.error("logback-cli.xml not found in classpath, applying default configuration"); + // Apply basic configuration + ch.qos.logback.classic.Logger rootLogger = context.getLogger(Logger.ROOT_LOGGER_NAME); + rootLogger.setLevel(ch.qos.logback.classic.Level.INFO); } - configurator.doConfigure(resource); + if (resource != null) { + configurator.doConfigure(resource); + } CqlLogAppender.start(context, libraryId -> CqlUtils.getLibrary(bundle, libraryId)); } catch (Exception e) { - logger.warn("Failed to configure logging", e); + logger.error("Failed to configure logging. This may impact application behavior", e); } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
Java/measureeval/src/main/java/com/lantanagroup/link/measureeval/FileSystemInvocation.java
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Analyze (java-kotlin)
- GitHub Check: Analyze (csharp)
🔇 Additional comments (2)
Java/measureeval/src/main/java/com/lantanagroup/link/measureeval/FileSystemInvocation.java (2)
19-19
: LGTM!The added import for java.net.URL is necessary for the URL handling in the configureLogging method.
37-37
: Verify impact on other callers and similar patterns.Let's verify:
- Other callers of this method that might expect JoranException
- Similar patterns in the codebase that might need the same fix
✅ Verification successful
Change is localized with no external impact
The
configureLogging
method is:
- Private static and only called within FileSystemInvocation.java
- No similar patterns exist in the codebase that would need the same fix
- The logback configuration is specific to this CLI context
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check for other callers of configureLogging rg "configureLogging\(" --type java # Check for similar patterns of ClassLoader usage that might need the same fix ast-grep --pattern 'ClassLoader $_ = $_.getClassLoader()' # Check for other usages of logback-cli.xml rg "logback-cli.xml"Length of output: 727
🛠️ Description of Changes
Use the main thread's context class loader (rather than the system class loader) to resolve logback-cli.xml from the classpath. Otherwise resolution fails in a Spring Boot
repackage
d fat JAR, because the system class loader doesn't support reaching into nested JARs to find resources.🧪 Testing Performed
Ran an arbitrary evaluation via
java -jar
. Successfully reproduced the error before the fix; verified that the error was resolved after the fix.📓 Documentation Updated
N/A
Summary by CodeRabbit