Program: 17855
Project: 17855
Buggy source:
/** 
 * <p>Handles the   {@link ODataRequest} in a way that it results in a corresponding {@link ODataResponse}.</p> <p>This includes building of the   {@link com.sap.core.odata.api.processor.ODataContext ODataContext}, delegation of URI parsing and dispatching of the request internally.</p>
 * @param request the incoming request
 * @return the corresponding result
 * @throws ODataException
 */
public ODataResponse handle(final ODataRequest request) throws ODataException {
  ODataContextImpl context=buildODataContext(request);
  final int timingHandle=context.startRuntimeMeasurement("String_Node_Str","String_Node_Str");
  ODataResponse odataResponse;
  try {
    service=serviceFactory.createService(context);
    context.setService(service);
    service.getProcessor().setContext(context);
    final String serverDataServiceVersion=getServerDataServiceVersion();
    final String requestDataServiceVersion=context.getRequestHeader(ODataHttpHeaders.DATASERVICEVERSION);
    validateDataServiceVersion(serverDataServiceVersion,requestDataServiceVersion);
    UriParser uriParser=new UriParserImpl(service.getEntityDataModel());
    final List<PathSegment> pathSegments=context.getPathInfo().getODataSegments();
    int timingHandle2=context.startRuntimeMeasurement("String_Node_Str","String_Node_Str");
    final UriInfoImpl uriInfo=(UriInfoImpl)uriParser.parse(pathSegments,request.getQueryParameters());
    context.stopRuntimeMeasurement(timingHandle2);
    final ODataHttpMethod method=request.getMethod();
    timingHandle2=context.startRuntimeMeasurement("String_Node_Str","String_Node_Str");
    validateMethodAndUri(method,uriInfo);
    context.stopRuntimeMeasurement(timingHandle2);
    if (method == ODataHttpMethod.POST || method == ODataHttpMethod.PUT || method == ODataHttpMethod.PATCH || method == ODataHttpMethod.MERGE) {
      final ContentType requestContentType=ContentType.parse(request.getContentType());
      if (requestContentType == null) {
        throw new ODataBadRequestException(ODataBadRequestException.INVALID_HEADER.addContent(HttpHeaders.CONTENT_TYPE,request.getContentType()));
      }
 else {
        checkRequestContentType(uriInfo,requestContentType);
      }
    }
    final String acceptContentType=new ContentNegotiator().doContentNegotiation(uriInfo,request.getAcceptHeaders(),getSupportedContentTypes(uriInfo));
    Dispatcher dispatcher=new Dispatcher(service);
    timingHandle2=context.startRuntimeMeasurement("String_Node_Str","String_Node_Str");
    odataResponse=dispatcher.dispatch(method,uriInfo,request.getBody(),request.getContentType(),acceptContentType);
    context.stopRuntimeMeasurement(timingHandle2);
    final String location=(method == ODataHttpMethod.POST && (uriInfo.getUriType() == UriType.URI1 || uriInfo.getUriType() == UriType.URI6B)) ? odataResponse.getIdLiteral() : null;
    final HttpStatusCodes s=odataResponse.getStatus() == null ? method == ODataHttpMethod.POST ? uriInfo.getUriType() == UriType.URI9 ? HttpStatusCodes.OK : uriInfo.getUriType() == UriType.URI7B ? HttpStatusCodes.NO_CONTENT : HttpStatusCodes.CREATED : method == ODataHttpMethod.PUT || method == ODataHttpMethod.PATCH || method == ODataHttpMethod.MERGE || method == ODataHttpMethod.DELETE ? HttpStatusCodes.NO_CONTENT : HttpStatusCodes.OK : odataResponse.getStatus();
    ODataResponseBuilder extendedResponse=ODataResponse.fromResponse(odataResponse);
    if (!odataResponse.containsHeader(ODataHttpHeaders.DATASERVICEVERSION)) {
      extendedResponse=extendedResponse.header(ODataHttpHeaders.DATASERVICEVERSION,serverDataServiceVersion);
    }
    if (!odataResponse.containsHeader(HttpHeaders.LOCATION) && location != null) {
      extendedResponse=extendedResponse.header(HttpHeaders.LOCATION,location);
    }
    if (odataResponse.getStatus() != s) {
      extendedResponse=extendedResponse.status(s);
    }
    if (odataResponse.getETag() != null) {
      extendedResponse=extendedResponse.header(HttpHeaders.ETAG,odataResponse.getETag());
    }
    odataResponse=extendedResponse.build();
  }
 catch (  final Exception e) {
    ODataExceptionWrapper exceptionWrapper=new ODataExceptionWrapper(context,request.getQueryParameters(),request.getAcceptHeaders());
    odataResponse=exceptionWrapper.wrapInExceptionResponse(e);
  }
  context.stopRuntimeMeasurement(timingHandle);
  return odataResponse;
}

Fixed version (ground truth):
/** 
 * <p>Handles the   {@link ODataRequest} in a way that it results in a corresponding {@link ODataResponse}.</p> <p>This includes building of the   {@link com.sap.core.odata.api.processor.ODataContext ODataContext}, delegation of URI parsing and dispatching of the request internally.</p>
 * @param request the incoming request
 * @return the corresponding result
 * @throws ODataException
 */
public ODataResponse handle(final ODataRequest request) throws ODataException {
  ODataContextImpl context=buildODataContext(request);
  final int timingHandle=context.startRuntimeMeasurement("String_Node_Str","String_Node_Str");
  ODataResponse odataResponse;
  try {
    service=serviceFactory.createService(context);
    context.setService(service);
    service.getProcessor().setContext(context);
    final String serverDataServiceVersion=getServerDataServiceVersion();
    final String requestDataServiceVersion=context.getRequestHeader(ODataHttpHeaders.DATASERVICEVERSION);
    validateDataServiceVersion(serverDataServiceVersion,requestDataServiceVersion);
    UriParser uriParser=new UriParserImpl(service.getEntityDataModel());
    final List<PathSegment> pathSegments=context.getPathInfo().getODataSegments();
    int timingHandle2=context.startRuntimeMeasurement("String_Node_Str","String_Node_Str");
    final UriInfoImpl uriInfo=(UriInfoImpl)uriParser.parse(pathSegments,request.getQueryParameters());
    context.stopRuntimeMeasurement(timingHandle2);
    final ODataHttpMethod method=request.getMethod();
    timingHandle2=context.startRuntimeMeasurement("String_Node_Str","String_Node_Str");
    validateMethodAndUri(method,uriInfo);
    context.stopRuntimeMeasurement(timingHandle2);
    if (method == ODataHttpMethod.POST || method == ODataHttpMethod.PUT || method == ODataHttpMethod.PATCH || method == ODataHttpMethod.MERGE) {
      final ContentType requestContentType=ContentType.parse(request.getContentType());
      if (requestContentType == null) {
        throw new ODataBadRequestException(ODataBadRequestException.INVALID_HEADER.addContent(HttpHeaders.CONTENT_TYPE,request.getContentType()));
      }
 else {
        checkRequestContentType(uriInfo,requestContentType);
      }
    }
    final String acceptContentType=doContentNegotiation(request,uriInfo);
    Dispatcher dispatcher=new Dispatcher(service);
    timingHandle2=context.startRuntimeMeasurement("String_Node_Str","String_Node_Str");
    odataResponse=dispatcher.dispatch(method,uriInfo,request.getBody(),request.getContentType(),acceptContentType);
    context.stopRuntimeMeasurement(timingHandle2);
    final String location=(method == ODataHttpMethod.POST && (uriInfo.getUriType() == UriType.URI1 || uriInfo.getUriType() == UriType.URI6B)) ? odataResponse.getIdLiteral() : null;
    final HttpStatusCodes s=odataResponse.getStatus() == null ? method == ODataHttpMethod.POST ? uriInfo.getUriType() == UriType.URI9 ? HttpStatusCodes.OK : uriInfo.getUriType() == UriType.URI7B ? HttpStatusCodes.NO_CONTENT : HttpStatusCodes.CREATED : method == ODataHttpMethod.PUT || method == ODataHttpMethod.PATCH || method == ODataHttpMethod.MERGE || method == ODataHttpMethod.DELETE ? HttpStatusCodes.NO_CONTENT : HttpStatusCodes.OK : odataResponse.getStatus();
    ODataResponseBuilder extendedResponse=ODataResponse.fromResponse(odataResponse);
    if (!odataResponse.containsHeader(ODataHttpHeaders.DATASERVICEVERSION)) {
      extendedResponse=extendedResponse.header(ODataHttpHeaders.DATASERVICEVERSION,serverDataServiceVersion);
    }
    if (!odataResponse.containsHeader(HttpHeaders.LOCATION) && location != null) {
      extendedResponse=extendedResponse.header(HttpHeaders.LOCATION,location);
    }
    if (odataResponse.getStatus() != s) {
      extendedResponse=extendedResponse.status(s);
    }
    if (odataResponse.getETag() != null) {
      extendedResponse=extendedResponse.header(HttpHeaders.ETAG,odataResponse.getETag());
    }
    odataResponse=extendedResponse.build();
  }
 catch (  final Exception e) {
    ODataExceptionWrapper exceptionWrapper=new ODataExceptionWrapper(context,request.getQueryParameters(),request.getAcceptHeaders());
    odataResponse=exceptionWrapper.wrapInExceptionResponse(e);
  }
  context.stopRuntimeMeasurement(timingHandle);
  return odataResponse;
}