Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Observation.getEffectiveDateTimeType throwing NullPointerException when EffectiveDateTime is null [v 3.0.0, 3.2.0] #846
Calling Observation.getEffectiveDateTimeType on an Observation with a null effectiveDateTime value results in a NullPointerException. The exception is thrown as the effective value is de-referenced to get the classname for the FHIRException message:
I would likely expect a null return for a null value in this case. Or at the least a FHIRException thrown rather than NPE.
Code in question is at line Observation.java:2125:
Looking closer into Observation.java, it looks like many of the methods follow the same pattern and will have the same issue when dealing with null values.
I checked Patient as well and Patient.getDeceasedBooleanType and Patient.getDeceasedDateTimeType are the same.
So for all these, users would need to call hasXXX() prior to getXXX() to avoid the NPE. Again, I'd rather receive a null for these cases, or 2nd choice would be the FHIRException since it's a checked exception and has to be dealt with anyway. Many users might not think to check for null or a NPE in these cases, especially since they already have to try-catch a FHIRException to use these methods.
If my conclusions are correct, I'm kind of surprised that nobody else has run into this though. Which gives me a little pause that I'm not overlooking something..