-
Notifications
You must be signed in to change notification settings - Fork 118
Fixes Error prone null checks in Bunsen module #1491
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
base: master
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
bashir2
left a comment
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.
Just sharing some preliminary comments as we discussed.
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.
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?
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.
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
bunsen/bunsen-avro/src/main/java/com/cerner/bunsen/avro/converters/DefinitionToAvroVisitor.java
Outdated
Show resolved
Hide resolved
bunsen/bunsen-avro/src/main/java/com/cerner/bunsen/avro/tools/GenerateAggregatedSchemas.java
Show resolved
Hide resolved
|
/gcbrun |
|
/gcbrun |
bunsen/bunsen-avro/src/main/java/com/cerner/bunsen/avro/tools/GenerateAggregatedSchemas.java
Show resolved
Hide resolved
| AvroConverter.forResources(fhirContext, patientProfiles, 1); | ||
|
|
||
| avroBunsenTestProfilePatient = | ||
| Record testBunsenTestProfilePatientRecord = |
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.
nit: What is the benefit of the new aux variable testBunsenTestProfilePatientRecord? If none, then revert it?
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.
We need the variable in order to assert for null before proceeding with the rest of the logic.
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.
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); |
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.
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.
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.
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 |
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.
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. |
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.
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; |
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.
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; |
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.
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; |
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.
ditto
| * @return the HAPI equivalent. | ||
| */ | ||
| IBase toHapi(Object input); | ||
| @Nullable IBase toHapi(Object input); |
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.
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 |
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.
Leaving this comment here to make sure we resolve this TODO before merge.
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 packageright before creating this pull request andadded all formatting changes to my commit.
If I made any Python code changes, I ran
black .andpylint .rightbefore 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