added nullchecks to prevent NPE (#2417)

* added nullchecks to prevent NPE
fixes #2171

* Add test from #2171 and changelog

Co-authored-by: jamesagnew <jamesagnew@gmail.com>
This commit is contained in:
Patrick Werner 2021-02-24 16:09:04 +01:00 committed by GitHub
parent 8f474d11b8
commit cf1f2f27db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
type: fix
issue: 2417
title: "A NullPointerException was corrected when indexing resources containing an indexed Period field that
had a start but not an end defined."

View File

@ -1496,6 +1496,43 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
}
@Test
public void testPeriodWithNoStart() {
ServiceRequest serviceRequest = new ServiceRequest();
Period period = new Period();
period.setEnd(new Date());
Timing timing = new Timing();
timing.setRepeat(new Timing.TimingRepeatComponent().setBounds(period));
serviceRequest.setOccurrence(timing);
// Should not crash
myServiceRequestDao.create(serviceRequest);
runInTransaction(()->{
assertEquals(1, myResourceIndexedSearchParamDateDao.findAll().size());
});
}
@Test
public void testPeriodWithNoEnd() {
ServiceRequest serviceRequest = new ServiceRequest();
Period period = new Period();
period.setStart(new Date());
Timing timing = new Timing();
timing.setRepeat(new Timing.TimingRepeatComponent().setBounds(period));
serviceRequest.setOccurrence(timing);
// Should not crash
myServiceRequestDao.create(serviceRequest);
runInTransaction(()->{
assertEquals(1, myResourceIndexedSearchParamDateDao.findAll().size());
});
}
@Test
public void testSearchByIdParamInverse() {
String id1;

View File

@ -1364,8 +1364,12 @@ public abstract class BaseSearchParamExtractor implements ISearchParamExtractor
if ("Period".equals(boundsType)) {
Date start = extractValueAsDate(myPeriodStartValueChild, bounds.get());
Date end = extractValueAsDate(myPeriodEndValueChild, bounds.get());
dates.add(start);
if (start != null) {
dates.add(start);
}
if (end != null) {
dates.add(end);
}
}
}
}