Skip to content

Conversation

@ndegwamartin
Copy link
Collaborator

Description of what I changed

Resolves #1474

E2E test

TESTED:

Please replace this with a description of how you tested your PR beyond the
automated e2e/unit tests.

Checklist: I completed these to help reviewers :)

  • I have read and will follow the
    review process.

  • I am familiar with Google Style Guides for the language I have coded in.

    No? Please take some time and review
    Java and
    Python style guides.

  • My IDE is configured to follow the Google
    code styles.

    No? Unsure? ->
    configure your IDE.

  • I have added tests to cover my changes. (If you refactored existing
    code that was well tested you do not have to add tests)

  • I ran mvn clean package right before creating this pull request and
    added all formatting changes to my commit.

  • If I made any Python code changes, I ran black . and pylint . right
    before creating this pull request and added all formatting changes to my
    commit.

  • All new and existing tests passed.

  • My pull request is based on the latest changes of the master branch.

    No? Unsure? -> execute command git pull --rebase upstream master

@ndegwamartin ndegwamartin requested a review from bashir2 October 6, 2025 17:24
@codecov-commenter
Copy link

codecov-commenter commented Oct 6, 2025

Codecov Report

❌ Patch coverage is 45.09804% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.40%. Comparing base (c3e8a91) to head (d3200dc).

Files with missing lines Patch % Lines
...erner/bunsen/definitions/StructureDefinitions.java 36.36% 2 Missing and 5 partials ⚠️
...ner/bunsen/definitions/HapiCompositeConverter.java 60.00% 0 Missing and 6 partials ⚠️
...ner/bunsen/definitions/HapiContainedConverter.java 0.00% 6 Missing ⚠️
...r/bunsen/avro/tools/GenerateAggregatedSchemas.java 0.00% 3 Missing ⚠️
...a/com/cerner/bunsen/definitions/EnumConverter.java 0.00% 0 Missing and 2 partials ⚠️
...bunsen/definitions/r4/R4FhirConversionSupport.java 0.00% 1 Missing ⚠️
...en/definitions/stu3/Stu3FhirConversionSupport.java 0.00% 1 Missing ⚠️
...java/com/cerner/bunsen/ProfileMappingProvider.java 88.88% 0 Missing and 1 partial ⚠️
...cerner/bunsen/definitions/HapiChoiceConverter.java 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1491      +/-   ##
============================================
- Coverage     46.52%   46.40%   -0.12%     
- Complexity      677      679       +2     
============================================
  Files            90       90              
  Lines          5892     5913      +21     
  Branches        826      844      +18     
============================================
+ Hits           2741     2744       +3     
- Misses         2843     2848       +5     
- Partials        308      321      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ndegwamartin ndegwamartin marked this pull request as ready for review October 10, 2025 17:22
Copy link
Collaborator

@bashir2 bashir2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just sharing some preliminary comments as we discussed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will get a NPE if getElementType() returns null here; so we should handle it if we allow null in the base class; ditto on line 77 above. Can you please check all usages of getElementType and make sure that null is handled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All existing usages of getElementType are null safe.

For usages of FhirContext.getResourceDefinition specifically, there's a validation check for blankness which throws an IllegalArgument exception if it is, see https://hapifhir.io/hapi-fhir/apidocs/hapi-fhir-base/src-html/ca/uhn/fhir/context/FhirContext.html#line-594

@ndegwamartin
Copy link
Collaborator Author

/gcbrun

@ndegwamartin
Copy link
Collaborator Author

/gcbrun

AvroConverter.forResources(fhirContext, patientProfiles, 1);

avroBunsenTestProfilePatient =
Record testBunsenTestProfilePatientRecord =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: What is the benefit of the new aux variable testBunsenTestProfilePatientRecord? If none, then revert it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need the variable in order to assert for null before proceeding with the rest of the logic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other change is reducing the scope the variable from field to local for the specific test case using it.

fhirContext, R4UsCoreProfileData.US_CORE_OBSERVATION_PROFILES, 1);

avroObservation = (Record) observationConverter.resourceToAvro(testObservation);
Record record = (Record) observationConverter.resourceToAvro(testObservation);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Ditto here and elsewhere that you have added a new aux var; if there is a reason, feel free to keep them, if not please revert them to minimize the changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this case (and most of them), it is the approach we are using to satisfy NullAways nullability check, otherwise it fails, i.e.

    Record record = (Record) observationConverter.resourceToAvro(testObservation);
    Assert.assertNotNull(record);
    avroObservation = record;

}

@Override
@Nullable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't getFirstTypeProfile also be annotated as @Nullable?

private final Map<FhirVersionEnum, FhirContextData> fhirContextMappings;

@SuppressWarnings(
"NullAway.Init") // This is initialized/used via the singleton pattern getInstance method.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please move the comment to a separate line before the annotation (ditto below).

// Meta element.
values[valueIndex++] = schemaEntry.result().fromHapi(((IAnyResource) composite).getMeta());
Object value = schemaEntry.result().fromHapi(((IAnyResource) composite).getMeta());
if (value != null) values[valueIndex++] = value;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto; and I think there is a bigger problem here: When value == null we are skipping valueIndex++ hence creating a mismatch between the values and children list sizes (which I think can cause other issues later in the code, if we break this invariant). In general, I would suggest that null related fixes should either be a no-op or some tests added for code changes to make sure we are not unintentionally introducing new bugs.


values[valueIndex] = schemaEntry.result().fromHapi(propertyValues);
Object value = schemaEntry.result().fromHapi(propertyValues);
if (value != null) values[valueIndex] = value;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto here and below

values[valueIndex] = schemaEntry.result().fromHapi(composite);
if (schemaEntry != null) {
Object value = schemaEntry.result().fromHapi(composite);
if (value != null) values[valueIndex] = value;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

* @return the HAPI equivalent.
*/
IBase toHapi(Object input);
@Nullable IBase toHapi(Object input);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please be consistent with how you place the @Nullable annotation, e.g., always place it in a separate line (like you have done elsewhere).

* data in siblings.)
*/
// TODO perform a deep review of this method's code and the implication of various nullability
// check approaches
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this comment here to make sure we resolve this TODO before merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix NullAway Warnings for Null Pointer Exceptions

3 participants