Skip to content

Commit

Permalink
LNK-3334: Error occurred while evaluating measure: Cannot invoke "jav…
Browse files Browse the repository at this point in the history
…a.net.URL.openConnection()" because "url" is null (#607)

### 🛠️ 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

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
	- Improved logging configuration error handling
- Enhanced logging resilience by preventing application failure due to
missing configuration files
	- Implemented more robust exception management during logging setup

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
smailliwcs authored Jan 8, 2025
2 parents a696f24 + 21991f2 commit b37072f
Showing 1 changed file with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand All @@ -33,13 +34,23 @@ public class FileSystemInvocation {
private static final FhirContext fhirContext = FhirContext.forR4Cached();
private static final Logger logger = LoggerFactory.getLogger(FileSystemInvocation.class);

private static void configureLogging(Bundle bundle) throws JoranException {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
context.reset();
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(context);
configurator.doConfigure(ClassLoader.getSystemResource("logback-cli.xml"));
CqlLogAppender.start(context, libraryId -> CqlUtils.getLibrary(bundle, libraryId));
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;
}
configurator.doConfigure(resource);
CqlLogAppender.start(context, libraryId -> CqlUtils.getLibrary(bundle, libraryId));
} catch (Exception e) {
logger.warn("Failed to configure logging", e);
}
}

private static Bundle getBundle(String measureBundlePath) throws IOException {
Expand Down

0 comments on commit b37072f

Please sign in to comment.