nus-yam/ex-repair huggingface dataset:
Program: 141465
Project: 141465
Buggy source:
@Override public boolean isTypeKey(String typeKey){
  return hasText(typeKey) ? typeKey.equals(typeKey) : false;
}

Fixed version (ground truth):
@Override public boolean isTypeKey(String typeKey){
  return hasText(typeKey) ? this.typeKey.equals(typeKey) : false;
}
Program: 141466
Project: 141466
Buggy source:
public DefaultCrateTypeMapper(String typeKey){
  super(new CrateDocumentTypeAliasAccessor(typeKey));
}

Fixed version (ground truth):
public DefaultCrateTypeMapper(String typeKey){
  super(new CrateDocumentTypeAliasAccessor(typeKey));
  this.typeKey=typeKey;
}
Program: 141468
Project: 141468
Buggy source:
@Override public boolean isIdProperty(){
  return super.isIdProperty() || (field != null && SUPPORTED_ID_PROPERTY_NAMES.contains(getFieldName()));
}

Fixed version (ground truth):
@Override public boolean isIdProperty(){
  return super.isIdProperty() || (field != null && SUPPORTED_ID_PROPERTY_NAMES.contains(getName()));
}
Program: 141469
Project: 141469
Buggy source:
public SimpleCratePersistentProperty(Field field,PropertyDescriptor propertyDescriptor,PersistentEntity<?,CratePersistentProperty> owner,SimpleTypeHolder simpleTypeHolder){
  super(field,propertyDescriptor,owner,simpleTypeHolder);
}

Fixed version (ground truth):
public SimpleCratePersistentProperty(Field field,PropertyDescriptor propertyDescriptor,PersistentEntity<?,CratePersistentProperty> owner,SimpleTypeHolder simpleTypeHolder){
  super(field,propertyDescriptor,owner,simpleTypeHolder);
  if (isIdProperty() && getFieldName() != ID_FIELD_NAME) {
    logger.warn("String_Node_Str");
  }
}
Program: 141470
Project: 141470
Buggy source:
@Override public String getFieldName(){
  return field.getName();
}

Fixed version (ground truth):
@Override public String getFieldName(){
  if (isIdProperty()) {
    if (owner == null) {
      return ID_FIELD_NAME;
    }
    if (owner.getIdProperty() == null) {
      return ID_FIELD_NAME;
    }
    if (owner.isIdProperty(this)) {
      return ID_FIELD_NAME;
    }
  }
  return field.getName();
}
Program: 141471
Project: 141471
Buggy source:
private void columnToDotPath(Column column,Map<String,Column> map,String columnName){
  Iterator<Column> subColumns=column.getSubColumns().iterator();
  while (subColumns.hasNext()) {
    Column subColumn=subColumns.next();
    String dotPath=createdotPathKey(columnName,subColumn.getName());
    map.put(dotPath,subColumn);
    columnToDotPath(subColumn,map,dotPath);
  }
}

Fixed version (ground truth):
private void columnToDotPath(Column column,Map<String,Column> map,String columnName){
  Iterator<Column> subColumns=column.getSubColumns().iterator();
  while (subColumns.hasNext()) {
    Column subColumn=subColumns.next();
    String dotPath=createdotPathKey(columnName,subColumn.getName());
    logger.debug("String_Node_Str",dotPath);
    map.put(dotPath,subColumn);
    columnToDotPath(subColumn,map,dotPath);
  }
}
Program: 141472
Project: 141472
Buggy source:
/** 
 * Creates table definition containing table information and columns that are not found in   {@link TableMetadata}
 * @param entity instance used to generate table definition
 * @param tableMetadata metadata associated to the {@link CratePersistentEntity}
 * @return table with column definitions. If there is no difference in{@link CratePersistentEntity} instance and the {@link TableMetadata} information,null is returned
 */
public TableDefinition updateDefinition(CratePersistentEntity<?> entity,TableMetadata tableMetadata){
  List<Column> columns=entityColumnMapper.toColumns(entity);
  Map<String,Column> columnPaths=columnToDotPath(columns);
  Map<String,String> sqlPaths=sqlToDotPath(tableMetadata.getColumns());
  List<Column> additionalColumns=new LinkedList<Column>();
  Iterator<Entry<String,Column>> iterator=columnPaths.entrySet().iterator();
  while (iterator.hasNext()) {
    Entry<String,Column> columnPath=iterator.next();
    if (!sqlPaths.containsKey(columnPath.getKey())) {
      additionalColumns.add(columnPath.getValue());
      if (columnPath.getValue().isObjectColumn()) {
        removePropertyPaths(columnPath.getKey(),iterator);
      }
    }
  }
  return additionalColumns.isEmpty() ? null : new TableDefinition(entity.getTableName(),additionalColumns);
}

Fixed version (ground truth):
/** 
 * Creates table definition containing table information and columns that are not found in   {@link TableMetadata}
 * @param entity instance used to generate table definition
 * @param tableMetadata metadata associated to the {@link CratePersistentEntity}
 * @return table with column definitions. If there is no difference in{@link CratePersistentEntity} instance and the {@link TableMetadata} information,null is returned
 */
public TableDefinition updateDefinition(CratePersistentEntity<?> entity,TableMetadata tableMetadata){
  List<Column> columns=entityColumnMapper.toColumns(entity);
  Map<String,Column> columnPaths=columnToDotPath(columns);
  Map<String,String> sqlPaths=sqlToDotPath(tableMetadata.getColumns());
  List<Column> additionalColumns=new LinkedList<Column>();
  Iterator<Entry<String,Column>> iterator=columnPaths.entrySet().iterator();
  while (iterator.hasNext()) {
    Entry<String,Column> columnPath=iterator.next();
    if (!sqlPaths.containsKey(columnPath.getKey())) {
      logger.debug("String_Node_Str",columnPath.getKey());
      additionalColumns.add(columnPath.getValue());
      if (columnPath.getValue().isObjectColumn() || columnPath.getValue().isObjectArrayColumn()) {
        removePropertyPaths(columnPath.getKey(),iterator);
      }
    }
  }
  return additionalColumns.isEmpty() ? null : new TableDefinition(entity.getTableName(),additionalColumns);
}
Program: 141473
Project: 141473
Buggy source:
private Map<String,String> sqlToDotPath(List<ColumnMetadata> columns){
  Map<String,String> sqlPaths=new LinkedHashMap<String,String>(columns.size());
  for (  ColumnMetadata metadata : columns) {
    String dotPath=toDotPath(metadata.getSqlPath());
    String type=metadata.getCrateType();
    sqlPaths.put(dotPath,type);
  }
  return sqlPaths;
}

Fixed version (ground truth):
private Map<String,String> sqlToDotPath(List<ColumnMetadata> columns){
  Map<String,String> sqlPaths=new LinkedHashMap<String,String>(columns.size());
  for (  ColumnMetadata metadata : columns) {
    String dotPath=toDotPath(metadata.getSqlPath());
    String type=metadata.getCrateType();
    logger.debug("String_Node_Str",dotPath);
    sqlPaths.put(dotPath,type);
  }
  return sqlPaths;
}
Program: 141474
Project: 141474
Buggy source:
/** 
 * @param property The property to inspect 
 * @see VisitedPath#isCyclic(CratePersistentProperty)
 */
private VisitedPath getVisitedPath(CratePersistentProperty property){
  VisitedPath path=null;
  String type=property.getActualType().getName();
  if (visitedPaths.containsKey(type)) {
    List<VisitedPath> paths=visitedPaths.get(type);
    if (paths != null && !paths.isEmpty()) {
      for (      VisitedPath visitedPath : paths) {
        if (visitedPath.isCyclic(property)) {
          path=visitedPath;
          break;
        }
      }
    }
  }
  return path;
}

Fixed version (ground truth):
/** 
 * @param property The property to inspect 
 * @see VisitedPath#isCyclic(CratePersistentProperty)
 */
private VisitedPath getVisitedPath(CratePersistentProperty property){
  VisitedPath path=null;
  String propertyTypeKey=createKey(property);
  if (visitedPaths.containsKey(propertyTypeKey)) {
    List<VisitedPath> paths=visitedPaths.get(propertyTypeKey);
    if (paths != null && !paths.isEmpty()) {
      for (      VisitedPath visitedPath : paths) {
        if (visitedPath.isCyclic(property)) {
          path=visitedPath;
          break;
        }
      }
    }
  }
  return path;
}
Program: 141475
Project: 141475
Buggy source:
/** 
 * @param property The property to watch 
 * @throws CyclicReferenceException in case a potential cycle is detected.
 */
private void pushPath(CratePersistentProperty property){
  if (getVisitedPath(property) != null) {
    throw new CyclicReferenceException(property.getFieldName(),property.getOwner().getType(),dotPath);
  }
  String type=property.getActualType().getName();
  List<VisitedPath> paths=visitedPaths.get(type);
  if (paths == null) {
    paths=new LinkedList<VisitedPath>();
  }
  paths.add(new VisitedPath(property));
  if (!visitedPaths.containsKey(type)) {
    visitedPaths.put(type,paths);
  }
  if (hasText(dotPath)) {
    dotPath=dotPath.concat("String_Node_Str").concat(property.getFieldName());
  }
 else {
    dotPath=property.getFieldName();
  }
}

Fixed version (ground truth):
/** 
 * @param property The property to watch 
 * @throws CyclicReferenceException in case a potential cycle is detected.
 */
private void pushPath(CratePersistentProperty property){
  if (getVisitedPath(property) != null) {
    throw new CyclicReferenceException(property.getFieldName(),property.getOwner().getType(),dotPath);
  }
  String propertyTypeKey=createKey(property);
  List<VisitedPath> paths=visitedPaths.get(propertyTypeKey);
  if (paths == null) {
    paths=new LinkedList<VisitedPath>();
  }
  paths.add(new VisitedPath(property));
  if (!visitedPaths.containsKey(propertyTypeKey)) {
    visitedPaths.put(propertyTypeKey,paths);
  }
  if (hasText(dotPath)) {
    dotPath=dotPath.concat("String_Node_Str").concat(property.getFieldName());
  }
 else {
    dotPath=property.getFieldName();
  }
}
Program: 141476
Project: 141476
Buggy source:
@Scheduled(cron="String_Node_Str") public void updatePredictions(){
  log.info("String_Node_Str");
  TransactionTemplate txTemplate=new TransactionTemplate(transactionManager);
  txTemplate.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED);
  txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
  for (  Long predictorId : findPredictorsNeedingUpdate()) {
    Optional<Lock> lock=Optional.empty();
    try {
      lock=Optional.of(lockRepository.acquireLock("String_Node_Str" + predictorId,Duration.standardMinutes(1)));
      txTemplate.execute(tx -> {
        updatePredictor(predictorId);
        log.debug("String_Node_Str",predictorId);
        return null;
      }
);
    }
 catch (    LockException e) {
      log.debug("String_Node_Str",predictorId);
    }
catch (    Exception e) {
      log.error("String_Node_Str",predictorId,e);
    }
 finally {
      lock.ifPresent(l -> lockRepository.releaseLock(l));
    }
  }
}

Fixed version (ground truth):
@Scheduled(cron="String_Node_Str") public void updatePredictions(){
  Optional<Lock> lock=Optional.empty();
  try {
    lock=Optional.of(lockRepository.acquireLock("String_Node_Str",Duration.standardMinutes(2)));
  }
 catch (  LockException e) {
    log.debug("String_Node_Str");
    return;
  }
  log.info("String_Node_Str");
  TransactionTemplate txTemplate=new TransactionTemplate(transactionManager);
  txTemplate.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED);
  txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
  for (  Long predictorId : findPredictorsNeedingUpdate()) {
    try {
      txTemplate.execute(tx -> {
        updatePredictor(predictorId);
        log.debug("String_Node_Str",predictorId);
        return null;
      }
);
    }
 catch (    Exception e) {
      log.error("String_Node_Str",predictorId,e);
    }
 finally {
      lock.ifPresent(l -> lockRepository.releaseLock(l));
    }
  }
}
Program: 141477
Project: 141477
Buggy source:
@TransactionalWrite public void registerUtilization(long facilityId,List<Utilization> utilization,User currentUser){
  authorize(currentUser,repository.getFacilityInfo(facilityId),FACILITY_UTILIZATION_UPDATE);
  initUtilizationDefaults(facilityId,utilization);
  validateUtilizations(facilityId,utilization);
  utilizationRepository.insertUtilizations(utilization);
  predictionService.signalUpdateNeeded(utilization);
}

Fixed version (ground truth):
@TransactionalWrite public void registerUtilization(long facilityId,List<Utilization> utilization,User currentUser){
  final FacilityInfo facilityInfo=repository.getFacilityInfo(facilityId);
  authorize(currentUser,facilityInfo,FACILITY_UTILIZATION_UPDATE);
  initUtilizationDefaults(facilityId,utilization);
  validateUtilizations(facilityId,utilization);
  checkUtilizationApplicability(facilityInfo,utilization);
  utilizationRepository.insertUtilizations(utilization);
  predictionService.signalUpdateNeeded(utilization);
}
Program: 141478
Project: 141478
Buggy source:
@TransactionalRead public Set<Utilization> findLatestUtilization(long facilityId){
  return utilizationRepository.findLatestUtilization(facilityId);
}

Fixed version (ground truth):
@TransactionalRead public Set<Utilization> findLatestUtilization(long facilityId){
  final Facility facility=getFacility(facilityId);
  return utilizationRepository.findLatestUtilization(facilityId).stream().filter(u -> facility.builtCapacity.getOrDefault(u.capacityType,0) > 0).filter(u -> facility.usages.contains(u.usage)).collect(toSet());
}
Program: 141479
Project: 141479
Buggy source:
@RequestMapping(method=PUT,value=DEV_UTILIZATION) @TransactionalWrite public ResponseEntity<Void> generateUtilizationData(@NotNull @PathVariable(FACILITY_ID) Long facilityId){
  final Facility facility=facilityRepository.getFacility(facilityId);
  final Random random=new Random();
  final List<Utilization> utilizations=StreamSupport.stream(spliteratorUnknownSize(new DateTimeIterator(DateTime.now().minusMonths(1),DateTime.now(),Minutes.minutes(5)),Spliterator.ORDERED),false).flatMap(ts -> Stream.of(CAR,DISABLED,ELECTRIC_CAR).filter(facility.builtCapacity::containsKey).flatMap(capacityType -> {
    final Stream.Builder<UtilizationKey> builder=Stream.builder();
    builder.add(new UtilizationKey(facilityId,capacityType,Usage.PARK_AND_RIDE));
    if (capacityType == CAR) {
      builder.add(new UtilizationKey(facilityId,capacityType,Usage.HSL_TRAVEL_CARD));
    }
    return builder.build();
  }
).map(utilizationKey -> newUtilization(utilizationKey,facility.builtCapacity.get(utilizationKey.capacityType),ts.minusSeconds(random.nextInt(180))))).collect(toList());
  utilizationRepository.insertUtilizations(utilizations);
  predictionService.signalUpdateNeeded(utilizations);
  return new ResponseEntity<>(CREATED);
}

Fixed version (ground truth):
@RequestMapping(method=PUT,value=DEV_UTILIZATION) @TransactionalWrite public ResponseEntity<Void> generateUtilizationData(@NotNull @PathVariable(FACILITY_ID) Long facilityId){
  final Facility facility=facilityRepository.getFacility(facilityId);
  final Random random=new Random();
  final List<Utilization> utilizations=StreamSupport.stream(spliteratorUnknownSize(new DateTimeIterator(DateTime.now().minusMonths(1),DateTime.now(),Minutes.minutes(5)),Spliterator.ORDERED),false).flatMap(ts -> Stream.of(CAR,DISABLED,ELECTRIC_CAR).filter(facility.builtCapacity::containsKey).flatMap(capacityType -> {
    final Stream.Builder<UtilizationKey> builder=Stream.builder();
    builder.add(new UtilizationKey(facilityId,capacityType,Usage.PARK_AND_RIDE));
    if (capacityType == CAR) {
      builder.add(new UtilizationKey(facilityId,capacityType,Usage.COMMERCIAL));
    }
    return builder.build();
  }
).map(utilizationKey -> newUtilization(utilizationKey,facility.builtCapacity.get(utilizationKey.capacityType),ts.minusSeconds(random.nextInt(180))))).collect(toList());
  utilizationRepository.insertUtilizations(utilizations);
  predictionService.signalUpdateNeeded(utilizations);
  return new ResponseEntity<>(CREATED);
}
Program: 141480
Project: 141480
Buggy source:
@RequestMapping(method=GET,value=FACILITY_PREDICTION,produces=APPLICATION_JSON_VALUE) public ResponseEntity<List<PredictionResult>> getPrediction(@PathVariable(FACILITY_ID) long facilityId,@ModelAttribute @Valid PredictionRequest request){
  DateTime time=request.requestedTime();
  log.info("String_Node_Str",facilityId,time);
  List<PredictionBatch> predictions=predictionService.getPredictionsByFacility(facilityId,time);
  List<PredictionResult> results=predictions.stream().flatMap(pb -> PredictionResult.from(pb).stream()).collect(toList());
  return new ResponseEntity<>(results,OK);
}

Fixed version (ground truth):
@RequestMapping(method=GET,value=FACILITY_PREDICTION,produces=APPLICATION_JSON_VALUE) public ResponseEntity<List<PredictionResult>> getPrediction(@PathVariable(FACILITY_ID) long facilityId,@ModelAttribute @Valid PredictionRequest request){
  DateTime time=request.requestedTime();
  log.info("String_Node_Str",facilityId,time);
  List<PredictionResult> results=predictionService.getPredictionResultByFacility(facilityId,time);
  return new ResponseEntity<>(results,OK);
}
Program: 141481
Project: 141481
Buggy source:
@RequestMapping(method=GET,value=HUB_PREDICTION,produces=APPLICATION_JSON_VALUE) public ResponseEntity<List<HubPredictionResult>> getPrediction(@PathVariable(HUB_ID) long hubId,@ModelAttribute @Valid PredictionRequest request){
  DateTime time=request.requestedTime();
  log.info("String_Node_Str",hubId,time);
  final List<HubPredictionResult> results=hubService.getHub(hubId).facilityIds.stream().flatMap(facilityId -> predictionService.getPredictionsByFacility(facilityId,time).stream()).flatMap(pb -> PredictionResult.from(pb).stream()).collect(groupingBy(result -> result.capacityType.name() + result.usage.name())).values().stream().map(list -> HubPredictionResult.sumFrom(hubId,list)).collect(toList());
  return new ResponseEntity<>(results,OK);
}

Fixed version (ground truth):
@RequestMapping(method=GET,value=HUB_PREDICTION,produces=APPLICATION_JSON_VALUE) public ResponseEntity<List<HubPredictionResult>> getPrediction(@PathVariable(HUB_ID) long hubId,@ModelAttribute @Valid PredictionRequest request){
  DateTime time=request.requestedTime();
  log.info("String_Node_Str",hubId,time);
  final List<HubPredictionResult> results=hubService.getHub(hubId).facilityIds.stream().flatMap(facilityId -> predictionService.getPredictionResultByFacility(facilityId,time).stream()).collect(groupingBy(result -> result.capacityType.name() + result.usage.name())).values().stream().map(list -> HubPredictionResult.sumFrom(hubId,list)).collect(toList());
  return new ResponseEntity<>(results,OK);
}
Program: 141482
Project: 141482
Buggy source:
public static Utilization newUtilization(){
  Utilization u=new Utilization();
  u.capacityType=CapacityType.CAR;
  u.usage=Usage.HSL_TRAVEL_CARD;
  u.spacesAvailable=30;
  u.timestamp=new DateTime();
  return u;
}

Fixed version (ground truth):
public static Utilization newUtilization(){
  Utilization u=new Utilization();
  u.capacityType=CapacityType.CAR;
  u.usage=Usage.PARK_AND_RIDE;
  u.spacesAvailable=30;
  u.timestamp=new DateTime();
  return u;
}
Program: 141483
Project: 141483
Buggy source:
@Before public void initFixture(){
  devHelper.deleteAll();
  facilityId=dummies.createFacility();
  Long operatorId=facilityService.getFacility(facilityId).operatorId;
  user=devHelper.createOrUpdateUser(new NewUser(1L,"String_Node_Str",OPERATOR_API,operatorId,"String_Node_Str"));
  authToken=devHelper.login(user.username).token;
}

Fixed version (ground truth):
@Before public void initFixture(){
  devHelper.deleteAll();
  facilityId=dummies.createFacility();
  f=facilityService.getFacility(facilityId);
  Long operatorId=f.operatorId;
  user=devHelper.createOrUpdateUser(new NewUser(1L,"String_Node_Str",OPERATOR_API,operatorId,"String_Node_Str"));
  adminUser=devHelper.createOrUpdateUser(new NewUser(100l,"String_Node_Str",ADMIN,"String_Node_Str"));
  f.pricingMethod=PricingMethod.PARK_AND_RIDE_247_FREE;
  f.pricing=emptyList();
  facilityService.updateFacility(f.id,f,adminUser);
}
Program: 141485
Project: 141485
Buggy source:
@Test public void returns_predictions_for_all_capacity_types_and_usages(){
  makeDummyPredictions(Usage.HSL_TRAVEL_CARD);
  makeDummyPredictions(Usage.COMMERCIAL);
  PredictionResult[] predictions=getPredictions(facilityId);
  assertThat(predictions).hasSize(2);
}

Fixed version (ground truth):
@Test public void returns_predictions_for_all_capacity_types_and_usages(){
  makeDummyPredictions(Usage.HSL_TRAVEL_CARD);
  makeDummyPredictions(Usage.COMMERCIAL);
  f.builtCapacity=ImmutableMap.of(CAR,1000);
  f.pricingMethod=CUSTOM;
  f.pricing=asList(new Pricing(CAR,HSL_TRAVEL_CARD,1000,BUSINESS_DAY,"String_Node_Str","String_Node_Str","String_Node_Str"),new Pricing(CAR,HSL_TRAVEL_CARD,1000,SATURDAY,"String_Node_Str","String_Node_Str","String_Node_Str"),new Pricing(CAR,HSL_TRAVEL_CARD,1000,SUNDAY,"String_Node_Str","String_Node_Str","String_Node_Str"),new Pricing(CAR,COMMERCIAL,1000,BUSINESS_DAY,"String_Node_Str","String_Node_Str","String_Node_Str"),new Pricing(CAR,COMMERCIAL,1000,SATURDAY,"String_Node_Str","String_Node_Str","String_Node_Str"),new Pricing(CAR,COMMERCIAL,1000,SUNDAY,"String_Node_Str","String_Node_Str","String_Node_Str"));
  facilityService.updateFacility(f.id,f,adminUser);
  PredictionResult[] predictions=getPredictions(facilityId);
  assertThat(predictions).hasSize(2);
}
Program: 141486
Project: 141486
Buggy source:
@TransactionalRead public Set<Utilization> findLatestUtilization(long facilityId){
  final Facility facility=getFacility(facilityId);
  return utilizationRepository.findLatestUtilization(facilityId).stream().filter(u -> facility.builtCapacity.getOrDefault(u.capacityType,0) > 0).filter(u -> facility.usages.contains(u.usage)).collect(toSet());
}

Fixed version (ground truth):
@TransactionalRead public Set<Utilization> findLatestUtilization(long facilityId){
  final Facility facility=getFacility(facilityId);
  final Map<CapacityType,Set<Usage>> usagesByCapacityType=FacilityUtil.usagesByCapacityType(facility);
  return utilizationRepository.findLatestUtilization(facilityId).stream().filter(u -> usagesByCapacityType.getOrDefault(u.capacityType,emptySet()).contains(u.usage)).filter(u -> facility.builtCapacity.getOrDefault(u.capacityType,0) > 0).collect(toSet());
}
Program: 141487
Project: 141487
Buggy source:
/** 
 * Get the predictions by facility. Predictions that don't match the current built capacity or usage of the facility are left out.
 * @param facilityId the id of the facility
 * @param time the timestamp for the predictions
 * @return prediction results
 */
public List<PredictionResult> getPredictionResultByFacility(long facilityId,DateTime time){
  final Facility facility=facilityRepository.getFacility(facilityId);
  return getPredictionsByFacility(facilityId,time).stream().flatMap(pb -> PredictionResult.from(pb).stream()).filter(pr -> facility.usages.contains(pr.usage)).filter(pr -> facility.builtCapacity.getOrDefault(pr.capacityType,0) > 0).collect(toList());
}

Fixed version (ground truth):
/** 
 * Get the predictions by facility. Predictions that don't match the current built capacity or usage of the facility are left out.
 * @param facilityId the id of the facility
 * @param time the timestamp for the predictions
 * @return prediction results
 */
public List<PredictionResult> getPredictionResultByFacility(long facilityId,DateTime time){
  final Facility facility=facilityRepository.getFacility(facilityId);
  Map<CapacityType,Set<Usage>> usagesByCapacityType=FacilityUtil.usagesByCapacityType(facility);
  return getPredictionsByFacility(facilityId,time).stream().flatMap(pb -> PredictionResult.from(pb).stream()).filter(pr -> usagesByCapacityType.getOrDefault(pr.capacityType,emptySet()).contains(pr.usage)).filter(pr -> facility.builtCapacity.getOrDefault(pr.capacityType,0) > 0).collect(toList());
}
Program: 141488
Project: 141488
Buggy source:
@RequestMapping(method=PUT,value=DEV_UTILIZATION) @TransactionalWrite public ResponseEntity<Void> generateUtilizationData(@NotNull @PathVariable(FACILITY_ID) Long facilityId){
  final Facility facility=facilityRepository.getFacility(facilityId);
  final Random random=new Random();
  final List<Utilization> utilizations=StreamSupport.stream(spliteratorUnknownSize(new DateTimeIterator(DateTime.now().minusMonths(1),DateTime.now(),Minutes.minutes(5)),Spliterator.ORDERED),false).flatMap(ts -> Stream.of(CAR,DISABLED,ELECTRIC_CAR).filter(facility.builtCapacity::containsKey).flatMap(capacityType -> {
    final Stream.Builder<UtilizationKey> builder=Stream.builder();
    builder.add(new UtilizationKey(facilityId,capacityType,Usage.PARK_AND_RIDE));
    if (capacityType == CAR) {
      builder.add(new UtilizationKey(facilityId,capacityType,Usage.COMMERCIAL));
    }
    return builder.build();
  }
).map(utilizationKey -> newUtilization(utilizationKey,facility.builtCapacity.get(utilizationKey.capacityType),ts.minusSeconds(random.nextInt(180))))).collect(toList());
  utilizationRepository.insertUtilizations(utilizations);
  predictionService.signalUpdateNeeded(utilizations);
  return new ResponseEntity<>(CREATED);
}

Fixed version (ground truth):
@RequestMapping(method=PUT,value=DEV_UTILIZATION) @TransactionalWrite public ResponseEntity<Void> generateUtilizationData(@NotNull @PathVariable(FACILITY_ID) Long facilityId){
  final Facility facility=facilityRepository.getFacility(facilityId);
  final Random random=new Random();
  final List<Utilization> utilizations=StreamSupport.stream(spliteratorUnknownSize(new DateTimeIterator(DateTime.now().minusMonths(1),DateTime.now(),Minutes.minutes(5)),Spliterator.ORDERED),false).flatMap(ts -> facility.builtCapacity.keySet().stream().flatMap(capacityType -> {
    if (facility.pricingMethod == PricingMethod.PARK_AND_RIDE_247_FREE) {
      return Stream.of(new UtilizationKey(facilityId,capacityType,Usage.PARK_AND_RIDE));
    }
 else {
      return facility.pricing.stream().filter(pr -> pr.capacityType == capacityType).map(pr -> new UtilizationKey(facilityId,capacityType,pr.usage));
    }
  }
).map(utilizationKey -> newUtilization(utilizationKey,facility.builtCapacity.get(utilizationKey.capacityType),ts.minusSeconds(random.nextInt(180))))).collect(toList());
  utilizationRepository.insertUtilizations(utilizations);
  predictionService.signalUpdateNeeded(utilizations);
  return new ResponseEntity<>(CREATED);
}
Program: 141489
Project: 141489
Buggy source:
@Test public void hub_excludes_prediction_if_no_usage(){
  final long facility2Id=dummies.createFacility();
  final Long operator2Id=facilityService.getFacility(facility2Id).operatorId;
  final User user2=devHelper.createOrUpdateUser(new NewUser(2L,"String_Node_Str",OPERATOR_API,operator2Id,"String_Node_Str"));
  final long hubId=dummies.createHub(facilityId,facility2Id);
  makeDummyPredictions(Usage.PARK_AND_RIDE,facilityId,user);
  makeDummyPredictions(Usage.PARK_AND_RIDE,facility2Id,user2);
  makeDummyPredictions(Usage.COMMERCIAL,facility2Id,user2);
  final Facility f2=facilityService.getFacility(facility2Id);
  f2.builtCapacity=ImmutableMap.of(CAR,1000);
  f2.pricingMethod=PARK_AND_RIDE_247_FREE;
  f2.pricing=emptyList();
  facilityService.updateFacility(f2.id,f2,adminUser);
  final HubPredictionResult[] predictionsForHub=getPredictionsForHub(hubId);
  assertThat(predictionsForHub[0].hubId).isEqualTo(hubId);
  assertThat(predictionsForHub[0].capacityType).isEqualTo(CapacityType.CAR);
  assertIsNear(DateTime.now(),predictionsForHub[0].timestamp);
  assertThat(predictionsForHub).hasSize(1).extracting(hpr -> hpr.usage).containsExactly(PARK_AND_RIDE);
  final HubPredictionResult parkAndRide=predictionsForHub[0];
  assertThat(parkAndRide.spacesAvailable).isEqualTo(SPACES_AVAILABLE * 2);
}

Fixed version (ground truth):
@Test public void hub_excludes_prediction_if_no_usage(){
  final long facility2Id=dummies.createFacility();
  final Long operator2Id=facilityService.getFacility(facility2Id).operatorId;
  final User user2=devHelper.createOrUpdateUser(new NewUser(2L,"String_Node_Str",OPERATOR_API,operator2Id,"String_Node_Str"));
  final long hubId=dummies.createHub(facilityId,facility2Id);
  makeDummyPredictions(Usage.PARK_AND_RIDE,facilityId,user,CapacityType.CAR);
  makeDummyPredictions(Usage.PARK_AND_RIDE,facility2Id,user2,CapacityType.CAR);
  makeDummyPredictions(Usage.COMMERCIAL,facility2Id,user2,CapacityType.CAR);
  final Facility f2=facilityService.getFacility(facility2Id);
  f2.builtCapacity=ImmutableMap.of(CAR,1000);
  f2.pricingMethod=PARK_AND_RIDE_247_FREE;
  f2.pricing=emptyList();
  facilityService.updateFacility(f2.id,f2,adminUser);
  final HubPredictionResult[] predictionsForHub=getPredictionsForHub(hubId);
  assertThat(predictionsForHub[0].hubId).isEqualTo(hubId);
  assertThat(predictionsForHub[0].capacityType).isEqualTo(CapacityType.CAR);
  assertIsNear(DateTime.now(),predictionsForHub[0].timestamp);
  assertThat(predictionsForHub).hasSize(1).extracting(hpr -> hpr.usage).containsExactly(PARK_AND_RIDE);
  final HubPredictionResult parkAndRide=predictionsForHub[0];
  assertThat(parkAndRide.spacesAvailable).isEqualTo(SPACES_AVAILABLE * 2);
}
Program: 141491
Project: 141491
Buggy source:
private Utilization makeDummyPredictions(Usage usage,long facilityId,User user){
  Utilization u=new Utilization();
  u.facilityId=facilityId;
  u.capacityType=CapacityType.CAR;
  u.usage=usage;
  u.timestamp=now;
  u.spacesAvailable=SPACES_AVAILABLE;
  facilityService.registerUtilization(facilityId,Collections.singletonList(u),user);
  predictionService.updatePredictions();
  return u;
}

Fixed version (ground truth):
private Utilization makeDummyPredictions(Usage usage,long facilityId,User user,CapacityType capacityType){
  Utilization u=new Utilization();
  u.facilityId=facilityId;
  u.capacityType=capacityType;
  u.usage=usage;
  u.timestamp=now;
  u.spacesAvailable=SPACES_AVAILABLE;
  facilityService.registerUtilization(facilityId,Collections.singletonList(u),user);
  predictionService.updatePredictions();
  return u;
}
Program: 141492
Project: 141492
Buggy source:
@Test public void hub_excludes_prediction_if_no_built_capacity(){
  final long facility2Id=dummies.createFacility();
  final Long operator2Id=facilityService.getFacility(facility2Id).operatorId;
  final User user2=devHelper.createOrUpdateUser(new NewUser(2L,"String_Node_Str",OPERATOR_API,operator2Id,"String_Node_Str"));
  final long hubId=dummies.createHub(facilityId,facility2Id);
  makeDummyPredictions(Usage.PARK_AND_RIDE,facilityId,user);
  makeDummyPredictions(Usage.PARK_AND_RIDE,facility2Id,user2);
  makeDummyPredictions(Usage.COMMERCIAL,facility2Id,user2);
  final Facility f2=facilityService.getFacility(facility2Id);
  f2.pricing=emptyList();
  f2.pricingMethod=PricingMethod.PARK_AND_RIDE_247_FREE;
  f2.builtCapacity=ImmutableMap.of(CapacityType.BICYCLE,1);
  facilityService.updateFacility(f2.id,f2,adminUser);
  final HubPredictionResult[] predictionsForHub=getPredictionsForHub(hubId);
  assertThat(predictionsForHub).hasSize(1);
  assertThat(predictionsForHub[0].hubId).isEqualTo(hubId);
  assertThat(predictionsForHub[0].capacityType).isEqualTo(CapacityType.CAR);
  assertIsNear(DateTime.now(),predictionsForHub[0].timestamp);
  final HubPredictionResult parkAndRide=stream(predictionsForHub).filter(pred -> pred.usage == Usage.PARK_AND_RIDE).findFirst().get();
  assertThat(parkAndRide.spacesAvailable).isEqualTo(SPACES_AVAILABLE);
}

Fixed version (ground truth):
@Test public void hub_excludes_prediction_if_no_built_capacity(){
  final long facility2Id=dummies.createFacility();
  final Long operator2Id=facilityService.getFacility(facility2Id).operatorId;
  final User user2=devHelper.createOrUpdateUser(new NewUser(2L,"String_Node_Str",OPERATOR_API,operator2Id,"String_Node_Str"));
  final long hubId=dummies.createHub(facilityId,facility2Id);
  makeDummyPredictions(Usage.PARK_AND_RIDE,facilityId,user,CapacityType.CAR);
  makeDummyPredictions(Usage.PARK_AND_RIDE,facility2Id,user2,CapacityType.CAR);
  makeDummyPredictions(Usage.COMMERCIAL,facility2Id,user2,CapacityType.CAR);
  final Facility f2=facilityService.getFacility(facility2Id);
  f2.pricing=emptyList();
  f2.pricingMethod=PricingMethod.PARK_AND_RIDE_247_FREE;
  f2.builtCapacity=ImmutableMap.of(CapacityType.BICYCLE,1);
  facilityService.updateFacility(f2.id,f2,adminUser);
  final HubPredictionResult[] predictionsForHub=getPredictionsForHub(hubId);
  assertThat(predictionsForHub).hasSize(1);
  assertThat(predictionsForHub[0].hubId).isEqualTo(hubId);
  assertThat(predictionsForHub[0].capacityType).isEqualTo(CapacityType.CAR);
  assertIsNear(DateTime.now(),predictionsForHub[0].timestamp);
  final HubPredictionResult parkAndRide=stream(predictionsForHub).filter(pred -> pred.usage == Usage.PARK_AND_RIDE).findFirst().get();
  assertThat(parkAndRide.spacesAvailable).isEqualTo(SPACES_AVAILABLE);
}
Program: 141493
Project: 141493
Buggy source:
private void multiCapacityCreate(){
  DateTime now=DateTime.now();
  Utilization u1=new Utilization();
  u1.timestamp=now;
  u1.spacesAvailable=1;
  u1.capacityType=CapacityType.CAR;
  u1.usage=Usage.PARK_AND_RIDE;
  Utilization u2=new Utilization();
  u2.timestamp=now.minusSeconds(10);
  u2.spacesAvailable=1;
  u2.capacityType=CapacityType.BICYCLE;
  u2.usage=Usage.PARK_AND_RIDE;
  Utilization u3=new Utilization();
  u3.timestamp=now.minusSeconds(20);
  u3.spacesAvailable=2;
  u3.capacityType=CapacityType.ELECTRIC_CAR;
  u3.usage=Usage.PARK_AND_RIDE;
  List<Utilization> payload=Lists.newArrayList(u1,u2,u3);
  givenWithContent(authToken).body(payload).when().put(UrlSchema.FACILITY_UTILIZATION,f.id).then().statusCode(OK.value());
  Utilization[] results=getUtilizations();
  assertThat(results).extracting("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str").contains(tuple(f.id,u1.capacityType,u1.usage,u1.spacesAvailable,u1.timestamp.toInstant()),tuple(f.id,u2.capacityType,u2.usage,u2.spacesAvailable,u2.timestamp.toInstant()),tuple(f.id,u3.capacityType,u3.usage,u3.spacesAvailable,u3.timestamp.toInstant()));
}

Fixed version (ground truth):
private void multiCapacityCreate(Usage usageCar,Usage usageBike,Usage usageElectric){
  DateTime now=DateTime.now();
  Utilization u1=new Utilization();
  u1.timestamp=now;
  u1.spacesAvailable=1;
  u1.capacityType=CapacityType.CAR;
  u1.usage=usageCar;
  Utilization u2=new Utilization();
  u2.timestamp=now.minusSeconds(10);
  u2.spacesAvailable=1;
  u2.capacityType=CapacityType.BICYCLE;
  u2.usage=usageBike;
  Utilization u3=new Utilization();
  u3.timestamp=now.minusSeconds(20);
  u3.spacesAvailable=2;
  u3.capacityType=CapacityType.ELECTRIC_CAR;
  u3.usage=usageElectric;
  List<Utilization> payload=Lists.newArrayList(u1,u2,u3);
  registerUtilizations(payload);
  Utilization[] results=getUtilizations();
  assertThat(results).extracting("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str").contains(tuple(f.id,u1.capacityType,u1.usage,u1.spacesAvailable,u1.timestamp.toInstant()),tuple(f.id,u2.capacityType,u2.usage,u2.spacesAvailable,u2.timestamp.toInstant()),tuple(f.id,u3.capacityType,u3.usage,u3.spacesAvailable,u3.timestamp.toInstant()));
}
Program: 141494
Project: 141494
Buggy source:
private void updatePredictor(Long predictorId){
  PredictorState state=predictorRepository.getForUpdate(predictorId);
  state.moreUtilizations=false;
  getPredictor(state.predictorType).ifPresent(predictor -> {
    List<Prediction> predictions=predictor.predict(state,new UtilizationHistoryImpl(utilizationRepository,state.utilizationKey));
    predictionRepository.updatePredictions(toPredictionBatch(state,predictions),predictorId);
    predictorRepository.save(state);
  }
);
}

Fixed version (ground truth):
private void updatePredictor(Long predictorId){
  PredictorState state=predictorRepository.getForUpdate(predictorId);
  state.moreUtilizations=false;
  getPredictor(state.predictorType).ifPresent(predictor -> {
    List<Prediction> predictions=predictor.predict(state,new UtilizationHistoryImpl(utilizationRepository,state.utilizationKey));
    predictionRepository.updatePredictions(toPredictionBatch(state,predictions),predictorId);
  }
);
  predictorRepository.save(state);
}
Program: 141495
Project: 141495
Buggy source:
private void addRegionsSheet(Excel excel,List<Hub> hubs,Map<Long,List<Facility>> facilitiesByHubId){
  excel.addSheet("String_Node_Str",hubs,asList(col("String_Node_Str",h -> h.name),col("String_Node_Str",h -> addressText(h.address)),col("String_Node_Str",h -> h.location.getX()),col("String_Node_Str",h -> h.location.getY()),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,motorCapacities)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,bicycleCapacities)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,CAR)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,DISABLED)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,ELECTRIC_CAR)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,MOTORCYCLE)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,BICYCLE)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,BICYCLE_SECURE_SPACE)),col("String_Node_Str",h -> facilitiesByHubId.get(h.id).stream().map((  Facility f) -> f.name.fi).collect(toList()))));
}

Fixed version (ground truth):
private void addRegionsSheet(Excel excel,List<Hub> hubs,Map<Long,List<Facility>> facilitiesByHubId){
  excel.addSheet("String_Node_Str",hubs,asList(col("String_Node_Str",(  Hub h) -> h.name),col("String_Node_Str",(  Hub h) -> addressText(h.address)),col("String_Node_Str",(  Hub h) -> h.location.getX()),col("String_Node_Str",(  Hub h) -> h.location.getY()),col("String_Node_Str",(  Hub h) -> capcitySum(facilitiesByHubId,h.id,motorCapacities)),col("String_Node_Str",(  Hub h) -> capcitySum(facilitiesByHubId,h.id,bicycleCapacities)),col("String_Node_Str",(  Hub h) -> capcitySum(facilitiesByHubId,h.id,CAR)),col("String_Node_Str",(  Hub h) -> capcitySum(facilitiesByHubId,h.id,DISABLED)),col("String_Node_Str",(  Hub h) -> capcitySum(facilitiesByHubId,h.id,ELECTRIC_CAR)),col("String_Node_Str",(  Hub h) -> capcitySum(facilitiesByHubId,h.id,MOTORCYCLE)),col("String_Node_Str",(  Hub h) -> capcitySum(facilitiesByHubId,h.id,BICYCLE)),col("String_Node_Str",(  Hub h) -> capcitySum(facilitiesByHubId,h.id,BICYCLE_SECURE_SPACE)),col("String_Node_Str",(  Hub h) -> facilitiesByHubId.get(h.id).stream().map((  Facility f) -> f.name.fi).collect(toList()))));
}
Program: 141497
Project: 141497
Buggy source:
private void addRegionsSheet(Excel excel,List<Hub> hubs,Map<Long,List<Facility>> facilitiesByHubId){
  excel.addSheet("String_Node_Str",hubs,asList(col("String_Node_Str",h -> h.name),col("String_Node_Str",h -> addressText(h.address)),col("String_Node_Str",h -> h.location.getX()),col("String_Node_Str",h -> h.location.getY()),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,motorCapacities)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,bicycleCapacities)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,CAR)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,DISABLED)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,ELECTRIC_CAR)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,MOTORCYCLE)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,BICYCLE)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,BICYCLE_SECURE_SPACE)),col("String_Node_Str",h -> facilitiesByHubId.get(h.id).stream().map(f -> f.name.fi).collect(toList()))));
}

Fixed version (ground truth):
private void addRegionsSheet(Excel excel,List<Hub> hubs,Map<Long,List<Facility>> facilitiesByHubId){
  excel.addSheet("String_Node_Str",hubs,asList(col("String_Node_Str",h -> h.name),col("String_Node_Str",h -> addressText(h.address)),col("String_Node_Str",h -> h.location.getX()),col("String_Node_Str",h -> h.location.getY()),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,motorCapacities)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,bicycleCapacities)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,CAR)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,DISABLED)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,ELECTRIC_CAR)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,MOTORCYCLE)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,BICYCLE)),col("String_Node_Str",h -> capcitySum(facilitiesByHubId,h.id,BICYCLE_SECURE_SPACE)),col("String_Node_Str",h -> facilitiesByHubId.get(h.id).stream().map((  Facility f) -> f.name.fi).collect(toList()))));
}
Program: 141499
Project: 141499
Buggy source:
private int capcitySum(Map<Long,List<Facility>> facilitiesByHubId,long hubId,CapacityType... types){
  List<Facility> facilities=facilitiesByHubId.get(hubId);
  int sum=0;
  for (  CapacityType type : types) {
    sum+=facilities.stream().mapToInt(f -> f.builtCapacity.get(type)).sum();
  }
  return sum;
}

Fixed version (ground truth):
private int capcitySum(Map<Long,List<Facility>> facilitiesByHubId,long hubId,CapacityType... types){
  List<Facility> facilities=facilitiesByHubId.get(hubId);
  int sum=0;
  for (  CapacityType type : types) {
    sum+=facilities.stream().mapToInt((    Facility f) -> f.builtCapacity.get(type)).sum();
  }
  return sum;
}
Program: 141500
Project: 141500
Buggy source:
private List<Facility> getFacilities(){
  PageableFacilitySearch search=new PageableFacilitySearch();
  search.setLimit(10000);
  List<FacilityInfo> facilityInfos=facilityService.search(search).results;
  List<Facility> facilities=facilityInfos.stream().map(f -> facilityService.getFacility(f.id)).collect(toList());
  return facilities;
}

Fixed version (ground truth):
private List<Facility> getFacilities(){
  PageableFacilitySearch search=new PageableFacilitySearch();
  search.setLimit(10000);
  List<FacilityInfo> facilityInfos=facilityService.search(search).results;
  List<Facility> facilities=facilityInfos.stream().map((  Facility f) -> facilityService.getFacility(f.id)).collect(toList());
  return facilities;
}
Program: 141501
Project: 141501
Buggy source:
public byte[] reportHubsAndFacilities(User currentUser){
  authorize(currentUser,REPORT_GENERATE);
  List<Facility> facilities=getFacilities();
  List<Hub> hubs=getHubs();
  Map<Long,Facility> facilitiesByFacilityId=facilities.stream().collect(toMap(f -> f.id,identity()));
  Map<Long,List<Facility>> facilitiesByHubId=new HashMap<>();
  Map<Long,List<Hub>> hubsByFacilityId=new HashMap<>();
  hubs.stream().forEach(hub -> {
    facilitiesByHubId.put(hub.id,hub.facilityIds.stream().map(id -> facilitiesByFacilityId.get(id)).collect(toList()));
    for (    long facilityId : hub.facilityIds) {
      List<Hub> hubList=hubsByFacilityId.get(facilityId);
      if (hubList == null) {
        hubList=new ArrayList<>();
        hubsByFacilityId.put(facilityId,hubList);
      }
      hubList.add(hub);
    }
  }
);
  Excel excel=new Excel();
  addRegionsSheet(excel,hubs,facilitiesByHubId);
  addFacilitiesSheet(excel,facilities,hubsByFacilityId);
  excel.addSheet("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
  return excel.toBytes();
}

Fixed version (ground truth):
public byte[] reportHubsAndFacilities(User currentUser){
  authorize(currentUser,REPORT_GENERATE);
  List<Facility> facilities=getFacilities();
  List<Hub> hubs=getHubs();
  Map<Long,Facility> facilitiesByFacilityId=facilities.stream().collect(toMap((  Facility f) -> f.id,identity()));
  Map<Long,List<Facility>> facilitiesByHubId=new HashMap<>();
  Map<Long,List<Hub>> hubsByFacilityId=new HashMap<>();
  hubs.stream().forEach(hub -> {
    facilitiesByHubId.put(hub.id,hub.facilityIds.stream().map(id -> facilitiesByFacilityId.get(id)).collect(toList()));
    for (    long facilityId : hub.facilityIds) {
      List<Hub> hubList=hubsByFacilityId.get(facilityId);
      if (hubList == null) {
        hubList=new ArrayList<>();
        hubsByFacilityId.put(facilityId,hubList);
      }
      hubList.add(hub);
    }
  }
);
  Excel excel=new Excel();
  addRegionsSheet(excel,hubs,facilitiesByHubId);
  addFacilitiesSheet(excel,facilities,hubsByFacilityId);
  excel.addSheet("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
  return excel.toBytes();
}
Program: 141502
Project: 141502
Buggy source:
@TransactionalWrite public Set<Utilization> registerUtilization(long facilityId,List<Utilization> utilization,User currentUser){
  authorize(currentUser,repository.getFacilityInfo(facilityId),FACILITY_UTILIZATION_UPDATE);
  initUtilizationDefaults(facilityId,utilization);
  utilization.forEach(u -> validateUtilization(u,facilityId));
  utilizationRepository.insertUtilizations(utilization);
  predictionService.signalUpdateNeeded(utilization);
  return findLatestUtilization(facilityId);
}

Fixed version (ground truth):
@TransactionalWrite public Set<Utilization> registerUtilization(long facilityId,List<Utilization> utilization,User currentUser){
  authorize(currentUser,repository.getFacilityInfo(facilityId),FACILITY_UTILIZATION_UPDATE);
  initUtilizationDefaults(facilityId,utilization);
  validateUtilizations(facilityId,utilization);
  utilizationRepository.insertUtilizations(utilization);
  predictionService.signalUpdateNeeded(utilization);
  return findLatestUtilization(facilityId);
}
Program: 141503
Project: 141503
Buggy source:
private void validateUtilization(Utilization u,long expectedFacilityId){
  List<Violation> violations=new ArrayList<>();
  validationService.validate(u,violations);
  if (!Objects.equals(u.facilityId,expectedFacilityId)) {
    violations.add(new Violation("String_Node_Str","String_Node_Str","String_Node_Str" + expectedFacilityId + "String_Node_Str"+ u.facilityId));
  }
  if (isFarIntoFuture(u.timestamp)) {
    violations.add(new Violation("String_Node_Str","String_Node_Str",u.timestamp + "String_Node_Str" + DateTime.now()));
  }
  if (!violations.isEmpty()) {
    throw new ValidationException(violations);
  }
}

Fixed version (ground truth):
private List<Violation> validateUtilization(Utilization u,long expectedFacilityId){
  List<Violation> violations=new ArrayList<>();
  validationService.validate(u,violations);
  if (!Objects.equals(u.facilityId,expectedFacilityId)) {
    violations.add(new Violation("String_Node_Str","String_Node_Str","String_Node_Str" + expectedFacilityId + "String_Node_Str"+ u.facilityId));
  }
  if (isFarIntoFuture(u.timestamp)) {
    violations.add(new Violation("String_Node_Str","String_Node_Str",u.timestamp + "String_Node_Str" + DateTime.now()));
  }
  return violations;
}
Program: 141504
Project: 141504
Buggy source:
@Test public void timestamp_must_not_be_far_into_the_future(){
  givenWithContent(authToken).body(minValidPayload().put(Key.TIMESTAMP,DateTime.now().plusMinutes(3)).asArray()).when().put(UrlSchema.FACILITY_UTILIZATION,f.id).then().spec(assertResponse(HttpStatus.BAD_REQUEST,ValidationException.class)).body("String_Node_Str",is(Key.TIMESTAMP)).body("String_Node_Str",is("String_Node_Str"));
}

Fixed version (ground truth):
@Test public void timestamp_must_not_be_far_into_the_future(){
  givenWithContent(authToken).body(minValidPayload().put(Key.TIMESTAMP,DateTime.now().plusMinutes(3)).asArray()).when().put(UrlSchema.FACILITY_UTILIZATION,f.id).then().spec(assertResponse(HttpStatus.BAD_REQUEST,ValidationException.class)).body("String_Node_Str",is("String_Node_Str" + Key.TIMESTAMP)).body("String_Node_Str",is("String_Node_Str"));
}
Program: 141505
Project: 141505
Buggy source:
@Test public void capacity_type_is_required(){
  givenWithContent(authToken).body(minValidPayload().put(Key.CAPACITY_TYPE,null).asArray()).when().put(UrlSchema.FACILITY_UTILIZATION,f.id).then().spec(assertResponse(HttpStatus.BAD_REQUEST,ValidationException.class)).body("String_Node_Str",is(Key.CAPACITY_TYPE)).body("String_Node_Str",is("String_Node_Str"));
}

Fixed version (ground truth):
@Test public void capacity_type_is_required(){
  givenWithContent(authToken).body(minValidPayload().put(Key.CAPACITY_TYPE,null).asArray()).when().put(UrlSchema.FACILITY_UTILIZATION,f.id).then().spec(assertResponse(HttpStatus.BAD_REQUEST,ValidationException.class)).body("String_Node_Str",is("String_Node_Str" + Key.CAPACITY_TYPE)).body("String_Node_Str",is("String_Node_Str"));
}