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
|
@Test
|
||||||
public void testSearchByIdParamInverse() {
|
public void testSearchByIdParamInverse() {
|
||||||
String id1;
|
String id1;
|
||||||
|
|
|
@ -1364,11 +1364,15 @@ public abstract class BaseSearchParamExtractor implements ISearchParamExtractor
|
||||||
if ("Period".equals(boundsType)) {
|
if ("Period".equals(boundsType)) {
|
||||||
Date start = extractValueAsDate(myPeriodStartValueChild, bounds.get());
|
Date start = extractValueAsDate(myPeriodStartValueChild, bounds.get());
|
||||||
Date end = extractValueAsDate(myPeriodEndValueChild, bounds.get());
|
Date end = extractValueAsDate(myPeriodEndValueChild, bounds.get());
|
||||||
|
if (start != null) {
|
||||||
dates.add(start);
|
dates.add(start);
|
||||||
|
}
|
||||||
|
if (end != null) {
|
||||||
dates.add(end);
|
dates.add(end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!dates.isEmpty()) {
|
if (!dates.isEmpty()) {
|
||||||
myIndexedSearchParamDate = new ResourceIndexedSearchParamDate(myPartitionSettings, theResourceType, theSearchParam.getName(), dates.first(), firstValue, dates.last(), finalValue, firstValue);
|
myIndexedSearchParamDate = new ResourceIndexedSearchParamDate(myPartitionSettings, theResourceType, theSearchParam.getName(), dates.first(), firstValue, dates.last(), finalValue, firstValue);
|
||||||
|
|
Loading…
Reference in New Issue