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:
parent
8f474d11b8
commit
cf1f2f27db
|
@ -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."
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue