Program: 25700
Project: 25700
Buggy source:
@Override public ForwardCursorPagedResourceList<ScheduledActivity> getActivityHistoryV2(String activityGuid,String healthCode,DateTime scheduledOnOrAfter,DateTime scheduledOnOrBefore,Long offsetBy,int pageSize){
  checkNotNull(healthCode);
  checkNotNull(scheduledOnOrAfter);
  checkNotNull(scheduledOnOrBefore);
  checkNotNull(activityGuid);
  if (pageSize < API_MINIMUM_PAGE_SIZE || pageSize > API_MAXIMUM_PAGE_SIZE) {
    throw new BadRequestException(PAGE_SIZE_ERROR);
  }
  String healthCodeActivityGuid=healthCode + "String_Node_Str" + activityGuid;
  long startTimestamp=scheduledOnOrAfter.minusMillis(1).getMillis();
  long endTimestamp=scheduledOnOrBefore.plusMillis(1).getMillis();
  RangeKeyCondition dateRangeCondition=new RangeKeyCondition(SCHEDULED_ON_UTC).between(startTimestamp,endTimestamp);
  QuerySpec spec=new QuerySpec().withHashKey(new KeyAttribute(HEALTH_CODE_ACTIVITY_GUID,healthCodeActivityGuid)).withMaxPageSize(pageSize).withScanIndexForward(false).withRangeKeyCondition(dateRangeCondition);
  if (offsetBy != null) {
    RangeKeyCondition cursorPosCondition=new RangeKeyCondition(SCHEDULED_ON_UTC).gt(offsetBy);
    spec.withRangeKeyCondition(cursorPosCondition);
  }
  QueryOutcome queryOutcome=indexHelper.query(spec);
  List<Item> items=queryOutcome.getItems();
  QueryResult queryResult=queryOutcome.getQueryResult();
  List<ScheduledActivity> results=new ArrayList<>(items.size());
  for (  Item item : items) {
    ScheduledActivity activity=getActivity(healthCode,item.getString(GUID));
    results.add(activity);
  }
  Long nextPageOffsetBy=null;
  if (queryResult.getLastEvaluatedKey() != null) {
    nextPageOffsetBy=Long.parseLong(queryResult.getLastEvaluatedKey().get(SCHEDULED_ON_UTC).getN());
  }
  return new ForwardCursorPagedResourceList<ScheduledActivity>(results,nextPageOffsetBy,pageSize).withFilter(SCHEDULED_ON_OR_AFTER,scheduledOnOrAfter).withFilter(SCHEDULED_ON_OR_BEFORE,scheduledOnOrBefore);
}

Fixed version (ground truth):
@Override public ForwardCursorPagedResourceList<ScheduledActivity> getActivityHistoryV2(String healthCode,String activityGuid,DateTime scheduledOnOrAfter,DateTime scheduledOnOrBefore,Long offsetBy,int pageSize){
  checkNotNull(healthCode);
  checkNotNull(scheduledOnOrAfter);
  checkNotNull(scheduledOnOrBefore);
  checkNotNull(activityGuid);
  if (pageSize < API_MINIMUM_PAGE_SIZE || pageSize > API_MAXIMUM_PAGE_SIZE) {
    throw new BadRequestException(PAGE_SIZE_ERROR);
  }
  String healthCodeActivityGuid=healthCode + "String_Node_Str" + activityGuid;
  long startTimestamp=scheduledOnOrAfter.minusMillis(1).getMillis();
  long endTimestamp=scheduledOnOrBefore.plusMillis(1).getMillis();
  RangeKeyCondition dateRangeCondition=new RangeKeyCondition(SCHEDULED_ON_UTC).between(startTimestamp,endTimestamp);
  QuerySpec spec=new QuerySpec().withHashKey(new KeyAttribute(HEALTH_CODE_ACTIVITY_GUID,healthCodeActivityGuid)).withMaxResultSize(100000).withMaxPageSize(pageSize).withScanIndexForward(false).withRangeKeyCondition(dateRangeCondition);
  if (offsetBy != null) {
    RangeKeyCondition cursorPosCondition=new RangeKeyCondition(SCHEDULED_ON_UTC).lt(offsetBy);
    spec.withRangeKeyCondition(cursorPosCondition);
  }
  QueryOutcome queryOutcome=indexHelper.query(spec);
  List<Item> items=queryOutcome.getItems();
  QueryResult queryResult=queryOutcome.getQueryResult();
  List<ScheduledActivity> results=new ArrayList<>(items.size());
  for (  Item item : items) {
    ScheduledActivity activity=getActivity(healthCode,item.getString(GUID));
    activity.setTimeZone(DateTimeZone.UTC);
    results.add(activity);
  }
  Long nextPageOffsetBy=null;
  if (queryResult.getLastEvaluatedKey() != null) {
    nextPageOffsetBy=Long.parseLong(queryResult.getLastEvaluatedKey().get(SCHEDULED_ON_UTC).getN());
  }
  return new ForwardCursorPagedResourceList<ScheduledActivity>(results,nextPageOffsetBy,pageSize).withFilter(SCHEDULED_ON_OR_AFTER,scheduledOnOrAfter).withFilter(SCHEDULED_ON_OR_BEFORE,scheduledOnOrBefore);
}