Skip to content

Commit aaf9753

Browse files
authored
Fixed NPE when packaging a measure with an unresolvable primary library reference (#588)
1 parent 6d6da43 commit aaf9753

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

tooling/src/main/java/org/opencds/cqf/tooling/packaging/Package.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,23 @@ public void resolvePrimaryLibraryDependencies(IBaseResource mainArtifact, FhirCo
7979
var primaryLibrary = IOUtils.getLibraryUrlMap(fhirContext).get(
8080
ResourceUtils.getPrimaryLibraryUrl(mainArtifact, fhirContext));
8181
if (getPrimaryLibrary() == null) { // we want to save the primary library for the artifact being bundled not dependency libraries
82+
if (primaryLibrary == null && mainArtifact.getIdElement() != null && mainArtifact.getIdElement().getValue() != null) {
83+
logger.warn("Unable to resolve primary library for artifact {}", mainArtifact.getIdElement().getValue());
84+
}
8285
setPrimaryLibrary(primaryLibrary);
8386
}
8487

8588
var missingDependencies = new HashSet<String>();
8689
if (includeDependencies) {
87-
dependencies.add(primaryLibrary);
88-
var dependencyLibraries = ResourceUtils.getDepLibraryResources(
89-
primaryLibrary, fhirContext, true, false, missingDependencies);
90-
dependencies.addAll(dependencyLibraries.values());
90+
if (primaryLibrary != null) {
91+
dependencies.add(primaryLibrary);
92+
var dependencyLibraries = ResourceUtils.getDepLibraryResources(
93+
primaryLibrary, fhirContext, true, false, missingDependencies);
94+
dependencies.addAll(dependencyLibraries.values());
95+
}
9196
}
9297

93-
if (includeTerminology) {
98+
if (includeTerminology && primaryLibrary != null) {
9499
var dependencyValueSets = ResourceUtils.getDepValueSetResources(
95100
primaryLibrary, fhirContext, true, missingDependencies);
96101
dependencies.addAll(dependencyValueSets.values());

tooling/src/main/java/org/opencds/cqf/tooling/packaging/r4/PackageMeasure.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ public void output() {
116116
measureId + "-files");
117117
IOUtils.initializeDirectory(measureFilesOutputPath);
118118
IOUtils.writeResource(mainArtifact, measureFilesOutputPath, IOUtils.Encoding.JSON, getFhirContext());
119-
IOUtils.writeResource(getPrimaryLibrary(), measureFilesOutputPath, IOUtils.Encoding.JSON, getFhirContext());
119+
if (getPrimaryLibrary() != null) {
120+
IOUtils.writeResource(getPrimaryLibrary(), measureFilesOutputPath, IOUtils.Encoding.JSON, getFhirContext());
121+
}
120122

121123
// TODO: Is this correct? Do we just exclude the dependencies from the bundle?
122124
if (isIncludeDependencies()) {
@@ -134,9 +136,11 @@ public void output() {
134136
measureFilesOutputPath, IOUtils.Encoding.JSON, getFhirContext(), valueSetDependencyBundleId);
135137
}
136138

137-
var cqlFileOutputPath = IOUtils.concatFilePath(measureFilesOutputPath,
138-
((Library) getPrimaryLibrary()).getIdPart() + ".cql");
139-
IOUtils.writeCqlToFile(ResourceUtils.getCqlFromR4Library((Library) getPrimaryLibrary()), cqlFileOutputPath);
139+
if (getPrimaryLibrary() != null) {
140+
var cqlFileOutputPath = IOUtils.concatFilePath(measureFilesOutputPath,
141+
((Library) getPrimaryLibrary()).getIdPart() + ".cql");
142+
IOUtils.writeCqlToFile(ResourceUtils.getCqlFromR4Library((Library) getPrimaryLibrary()), cqlFileOutputPath);
143+
}
140144

141145
if (isIncludeTests() && testPackage != null) {
142146
logger.info("Packaging {} Tests...", testPackage.getTests().size());

0 commit comments

Comments
 (0)