hapifhir / hapi-fhir

🔥 HAPI FHIR - Java API for HL7 FHIR Clients and Servers
http://hapifhir.io
Apache License 2.0
2.04k stars 1.33k forks source link

FHIR Server: NullPointerException is thrown for search request with _getpagesoffset without _count #2140

Open tarasvuyiv opened 4 years ago

tarasvuyiv commented 4 years ago

Description The HAPI server throws a NullPointerException for the search requests containing more than one record when a _getpagesoffset parameter presented without the _count parameter.

How To Reproduce

  1. Create two Patients with POST requests.
  2. Call GET /Patient?_getpagesoffset=1.
  3. Examine the 500 status code OperationOutcome with no details.

Expected Behavior _getpagesoffset should be ignored and the search bundle returned. An OperationOtcome with a 400 status code and an appropriate issue diagnostic message.

Additional Details The exception is thrown at line 224 of the ca.uhn.fhir.rest.server.method.BaseResourceReturningMethodBinding class because theLimit variable is null.

if (theOffset > 0) {
  int start = Math.max(0, theOffset - theLimit);
  linkPrev = RestfulServerUtils.createPagingLink(theIncludes, theRequest, searchId, start, theLimit, theRequest.getParameters(), prettyPrint, theBundleType);
}

Environment:

jamesagnew commented 4 years ago

That URL is not valid. Paging links are not intended to be modified, and will always include a _count. I guess we should probably return an HTTP 400 instead of a 500 but this should not work.

tarasvuyiv commented 4 years ago

OK, I've updated the expected behavior.