Merge pull request #1047 from hdconradi/null-pointer-in-date-range-param
Fix NullPointerExceptions in DateRangeRaram
This commit is contained in:
commit
023877e09f
|
@ -255,7 +255,7 @@ public class DateRangeParam implements IQueryParameterAnd<DateParam> {
|
|||
}
|
||||
|
||||
public Date getLowerBoundAsInstant() {
|
||||
if (myLowerBound == null) {
|
||||
if (myLowerBound == null || myLowerBound.getValue() == null) {
|
||||
return null;
|
||||
}
|
||||
Date retVal = myLowerBound.getValue();
|
||||
|
@ -310,7 +310,7 @@ public class DateRangeParam implements IQueryParameterAnd<DateParam> {
|
|||
}
|
||||
|
||||
public Date getUpperBoundAsInstant() {
|
||||
if (myUpperBound == null) {
|
||||
if (myUpperBound == null || myUpperBound.getValue() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
package ca.uhn.fhir.rest.param;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.rest.api.QualifiedParamList;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class DateRangeParamTest {
|
||||
private FhirContext fhirContext;
|
||||
|
||||
@Before
|
||||
public void initMockContext() {
|
||||
fhirContext = Mockito.mock(FhirContext.class);
|
||||
}
|
||||
|
||||
/** Can happen e.g. when the query parameter for {@code _lastUpdated} is left empty. */
|
||||
@Test
|
||||
public void testParamWithoutPrefixAndWithoutValue() {
|
||||
QualifiedParamList qualifiedParamList = new QualifiedParamList(1);
|
||||
qualifiedParamList.add("");
|
||||
|
||||
List<QualifiedParamList> params = new ArrayList<>(1);
|
||||
params.add(qualifiedParamList);
|
||||
DateRangeParam dateRangeParam = new DateRangeParam();
|
||||
dateRangeParam.setValuesAsQueryTokens(fhirContext, "_lastUpdated", params);
|
||||
|
||||
assertTrue(dateRangeParam.isEmpty());
|
||||
}
|
||||
|
||||
/** Can happen e.g. when the query parameter for {@code _lastUpdated} is given as {@code lt} without any value. */
|
||||
@Test
|
||||
public void testUpperBoundWithPrefixWithoutValue() {
|
||||
QualifiedParamList qualifiedParamList = new QualifiedParamList(1);
|
||||
qualifiedParamList.add("lt");
|
||||
|
||||
List<QualifiedParamList> params = new ArrayList<>(1);
|
||||
params.add(qualifiedParamList);
|
||||
DateRangeParam dateRangeParam = new DateRangeParam();
|
||||
dateRangeParam.setValuesAsQueryTokens(fhirContext, "_lastUpdated", params);
|
||||
|
||||
assertTrue(dateRangeParam.isEmpty());
|
||||
}
|
||||
|
||||
/** Can happen e.g. when the query parameter for {@code _lastUpdated} is given as {@code gt} without any value. */
|
||||
@Test
|
||||
public void testLowerBoundWithPrefixWithoutValue() {
|
||||
QualifiedParamList qualifiedParamList = new QualifiedParamList(1);
|
||||
qualifiedParamList.add("gt");
|
||||
|
||||
List<QualifiedParamList> params = new ArrayList<>(1);
|
||||
params.add(qualifiedParamList);
|
||||
DateRangeParam dateRangeParam = new DateRangeParam();
|
||||
dateRangeParam.setValuesAsQueryTokens(fhirContext, "_lastUpdated", params);
|
||||
|
||||
assertTrue(dateRangeParam.isEmpty());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue