nus-yam/ex-repair huggingface dataset:
Program: 13126
Project: 13126
Buggy source:
public Iterator<B> getServices(Class<B> cls,ClassLoader clsLoader){
  Iterator<B> services=ServiceRegistry.lookupProviders(cls);
  if (!services.hasNext()) {
    services=ServiceRegistry.lookupProviders(cls,cls.getClass().getClassLoader());
  }
  if (!services.hasNext() && clsLoader != null) {
    services=ServiceRegistry.lookupProviders(cls,clsLoader);
  }
  return services;
}

Fixed version (ground truth):
public Iterator<B> getServices(Class<B> cls,ClassLoader clsLoader){
  Iterator<B> services=ServiceLoader.load(cls).iterator();
  if (!services.hasNext()) {
    services=ServiceLoader.load(cls,cls.getClass().getClassLoader()).iterator();
  }
  if (!services.hasNext() && clsLoader != null) {
    services=ServiceLoader.load(cls,clsLoader).iterator();
  }
  return services;
}
Program: 13127
Project: 13127
Buggy source:
/** 
 * Convert every key-value pair of a map into a string and append them all into a single string, in iteration order.
 */
@Test @Ignore public void c4_appendToMapValues(){
  Map<Integer,StringBuilder> map=new TreeMap<>();
  map.put(1,new StringBuilder("String_Node_Str"));
  map.put(2,new StringBuilder("String_Node_Str"));
  map.put(3,new StringBuilder("String_Node_Str"));
  assertEquals(3,map.size());
  assertTrue(map.values().stream().allMatch(x -> x instanceof StringBuilder));
  assertEquals("String_Node_Str",map.get(1).toString());
  assertEquals("String_Node_Str",map.get(2).toString());
  assertEquals("String_Node_Str",map.get(3).toString());
}

Fixed version (ground truth):
/** 
 * Given a map whose keys are Integers and whose values are StringBuilders, append to each StringBuilder the string representation of its corresponding Integer key. This should mutate each StringBuilder value in-place.
 */
@Test @Ignore public void c4_appendToMapValues(){
  Map<Integer,StringBuilder> map=new TreeMap<>();
  map.put(1,new StringBuilder("String_Node_Str"));
  map.put(2,new StringBuilder("String_Node_Str"));
  map.put(3,new StringBuilder("String_Node_Str"));
  assertEquals(3,map.size());
  assertTrue(map.values().stream().allMatch(x -> x instanceof StringBuilder));
  assertEquals("String_Node_Str",map.get(1).toString());
  assertEquals("String_Node_Str",map.get(2).toString());
  assertEquals("String_Node_Str",map.get(3).toString());
}
Program: 13128
Project: 13128
Buggy source:
/** 
 * Convert every key-value pair of a map into a string and append them all into a single string, in iteration order.
 */
@Test public void c4_appendToMapValues(){
  Map<Integer,StringBuilder> map=new TreeMap<>();
  map.put(1,new StringBuilder("String_Node_Str"));
  map.put(2,new StringBuilder("String_Node_Str"));
  map.put(3,new StringBuilder("String_Node_Str"));
  map.forEach((k,v) -> v.append(k));
  assertEquals(3,map.size());
  assertTrue(map.values().stream().allMatch(x -> x instanceof StringBuilder));
  assertEquals("String_Node_Str",map.get(1).toString());
  assertEquals("String_Node_Str",map.get(2).toString());
  assertEquals("String_Node_Str",map.get(3).toString());
}

Fixed version (ground truth):
/** 
 * Given a map whose keys are Integers and whose values are StringBuilders, append to each StringBuilder the string representation of its corresponding Integer key. This should mutate each StringBuilder value in-place.
 */
@Test public void c4_appendToMapValues(){
  Map<Integer,StringBuilder> map=new TreeMap<>();
  map.put(1,new StringBuilder("String_Node_Str"));
  map.put(2,new StringBuilder("String_Node_Str"));
  map.put(3,new StringBuilder("String_Node_Str"));
  map.forEach((k,v) -> v.append(k));
  assertEquals(3,map.size());
  assertTrue(map.values().stream().allMatch(x -> x instanceof StringBuilder));
  assertEquals("String_Node_Str",map.get(1).toString());
  assertEquals("String_Node_Str",map.get(2).toString());
  assertEquals("String_Node_Str",map.get(3).toString());
}
Program: 13129
Project: 13129
Buggy source:
public void disconnect(){
  if (connection != null) {
    try {
      connection.disconnect();
    }
 catch (    NotConnectedException ignored) {
      logger.debug("String_Node_Str");
    }
  }
}

Fixed version (ground truth):
public void disconnect(){
  if (connection != null) {
    try {
      connection.disconnect();
    }
 catch (    NotConnectedException ignored) {
      logger.debug("String_Node_Str");
    }
  }
  if (heartbeat != null) {
    heartbeat.cancel(false);
  }
}
Program: 13130
Project: 13130
Buggy source:
@Override public void run(){
  try {
    if (!connection.isConnected()) {
      if (heartbeat != null) {
        heartbeat.cancel(false);
      }
      return;
    }
    sendPing();
  }
 catch (  Exception e) {
    logger.warn("String_Node_Str",e);
  }
}

Fixed version (ground truth):
@Override public void run(){
  try {
    if (connection.isConnected()) {
      sendPing();
    }
  }
 catch (  Exception e) {
    logger.warn("String_Node_Str",e);
  }
}
Program: 13132
Project: 13132
Buggy source:
private <R extends OAPacket>R sendOAPacket(XMPPTCPConnection authConnection,OAPacket packet,Class<R> replyClass,long replyTimeout){
  PacketCollector collector=authConnection.createPacketCollector(new OAReplyFilter(packet,authConnection));
  try {
    authConnection.sendPacket(packet);
    return replyClass.cast(getNextPacketSkipContinues(collector,replyTimeout));
  }
 catch (  SmackException|XMPPErrorException e) {
    throw new RuntimeException("String_Node_Str",e);
  }
 finally {
    collector.cancel();
  }
}

Fixed version (ground truth):
private <R extends OAPacket>R sendOAPacket(XMPPTCPConnection authConnection,OAPacket packet,Class<R> replyClass,long replyTimeout){
  PacketCollector collector=authConnection.createPacketCollector(new OAReplyFilter(packet,authConnection));
  messageLock.lock();
  try {
    authConnection.sendPacket(packet);
    return replyClass.cast(getNextPacketSkipContinues(collector,replyTimeout));
  }
 catch (  SmackException|XMPPErrorException e) {
    throw new RuntimeException("String_Node_Str",e);
  }
 finally {
    messageLock.unlock();
    collector.cancel();
  }
}
Program: 13133
Project: 13133
Buggy source:
public NearestNeighborCollector(final E origin,final DistanceFunction<E> distanceFunction,final int capacity){
  if (capacity < 1) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.origin=origin;
  this.distanceFunction=distanceFunction;
  this.capacity=capacity;
  this.distanceComparator=new DistanceComparator<E>(origin,distanceFunction);
  this.priorityQueue=new PriorityQueue<E>(this.capacity,java.util.Collections.reverseOrder(this.distanceComparator));
}

Fixed version (ground truth):
public NearestNeighborCollector(final E queryPoint,final DistanceFunction<E> distanceFunction,final int capacity){
  if (capacity < 1) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.queryPoint=queryPoint;
  this.distanceFunction=distanceFunction;
  this.capacity=capacity;
  this.distanceComparator=new DistanceComparator<E>(queryPoint,distanceFunction);
  this.priorityQueue=new PriorityQueue<E>(this.capacity,java.util.Collections.reverseOrder(this.distanceComparator));
}
Program: 13134
Project: 13134
Buggy source:
public boolean remove(final E point){
  if (this.points == null) {
    final VPNode<E> childNode=this.getChildNodeForPoint(point);
    final boolean modified=childNode.remove(point);
    if (childNode.size() == 0) {
      final ArrayList<E> collectedPoints=new ArrayList<E>(this.size());
      this.addAllPointsToCollection(collectedPoints);
      this.threshold=this.thresholdSelectionStrategy.selectThreshold(collectedPoints,this.vantagePoint,this.distanceFunction);
      try {
        final int firstIndexPastThreshold=VPNode.partitionPoints(collectedPoints,this.vantagePoint,this.threshold,this.distanceFunction);
        this.closer=new VPNode<E>(collectedPoints.subList(0,firstIndexPastThreshold),this.distanceFunction,this.thresholdSelectionStrategy,this.capacity);
        this.farther=new VPNode<E>(collectedPoints.subList(firstIndexPastThreshold,collectedPoints.size()),this.distanceFunction,this.thresholdSelectionStrategy,this.capacity);
      }
 catch (      PartitionException e) {
        this.closer=null;
        this.farther=null;
        this.points=collectedPoints;
      }
    }
    return modified;
  }
 else {
    return this.points.remove(point);
  }
}

Fixed version (ground truth):
public boolean remove(final E point){
  if (this.points == null) {
    final VPNode<E> childNode=this.getChildNodeForPoint(point);
    final boolean modified=childNode.remove(point);
    if (childNode.size() == 0) {
      this.redistributePointsFromChildNodes();
    }
    return modified;
  }
 else {
    return this.points.remove(point);
  }
}
Program: 13135
Project: 13135
Buggy source:
public void collectNearestNeighbors(final E queryPoint,final NearestNeighborCollector<E> collector){
  if (this.points == null) {
    final VPNode<E> firstNodeSearched=this.getChildNodeForPoint(queryPoint);
    firstNodeSearched.collectNearestNeighbors(queryPoint,collector);
    final double distanceFromVantagePointToQueryPoint=this.distanceFunction.getDistance(this.vantagePoint,queryPoint);
    final double distanceFromQueryPointToFarthestPoint=this.distanceFunction.getDistance(queryPoint,collector.getFarthestPoint());
    if (firstNodeSearched == this.closer) {
      final double distanceFromQueryPointToThreshold=this.threshold - distanceFromVantagePointToQueryPoint;
      if (distanceFromQueryPointToFarthestPoint > distanceFromQueryPointToThreshold) {
        this.farther.collectNearestNeighbors(queryPoint,collector);
      }
    }
 else {
      double distanceFromQueryPointToThreshold=distanceFromVantagePointToQueryPoint - this.threshold;
      if (distanceFromQueryPointToThreshold <= distanceFromQueryPointToFarthestPoint) {
        this.closer.collectNearestNeighbors(queryPoint,collector);
      }
    }
  }
 else {
    for (    final E point : this.points) {
      collector.offerPoint(point);
    }
  }
}

Fixed version (ground truth):
public void collectNearestNeighbors(final NearestNeighborCollector<E> collector){
  if (this.points == null) {
    final VPNode<E> firstNodeSearched=this.getChildNodeForPoint(collector.getQueryPoint());
    firstNodeSearched.collectNearestNeighbors(collector);
    final double distanceFromVantagePointToQueryPoint=this.distanceFunction.getDistance(this.vantagePoint,collector.getQueryPoint());
    final double distanceFromQueryPointToFarthestPoint=this.distanceFunction.getDistance(collector.getQueryPoint(),collector.getFarthestPoint());
    if (firstNodeSearched == this.closer) {
      final double distanceFromQueryPointToThreshold=this.threshold - distanceFromVantagePointToQueryPoint;
      if (distanceFromQueryPointToFarthestPoint > distanceFromQueryPointToThreshold) {
        this.farther.collectNearestNeighbors(collector);
      }
    }
 else {
      double distanceFromQueryPointToThreshold=distanceFromVantagePointToQueryPoint - this.threshold;
      if (distanceFromQueryPointToThreshold <= distanceFromQueryPointToFarthestPoint) {
        this.closer.collectNearestNeighbors(collector);
      }
    }
  }
 else {
    for (    final E point : this.points) {
      collector.offerPoint(point);
    }
  }
}
Program: 13136
Project: 13136
Buggy source:
public boolean retainAll(final Collection<?> points){
  return this.points == null ? this.closer.retainAll(points) || this.farther.retainAll(points) : this.points.retainAll(points);
}

Fixed version (ground truth):
public boolean retainAll(final Collection<?> points){
  final boolean modified;
  if (this.points == null) {
    final boolean modifiedCloser=this.closer.retainAll(points);
    final boolean modifiedFarther=this.farther.retainAll(points);
    modified=modifiedCloser || modifiedFarther;
    if ((this.closer.size() == 0 || this.farther.size() == 0) && this.size() > 0) {
      this.redistributePointsFromChildNodes();
    }
  }
 else {
    modified=this.points.retainAll(points);
  }
  return modified;
}
Program: 13138
Project: 13138
Buggy source:
/** 
 * Generates a unique signature of a collection of types.
 */
private static String createTypeCollectionId(Collection<? extends Type> types){
  return types.stream().sorted(comparing(CdiSpiHelper::createTypeId)).map(CdiSpiHelper::createTypeId).collect(joining("String_Node_Str","String_Node_Str","String_Node_Str"));
}

Fixed version (ground truth):
/** 
 * Generates a unique signature of a collection of types.
 */
private static String createTypeCollectionId(Collection<Type> types){
  return types.stream().sorted(comparing(CdiSpiHelper::createTypeId)).map(CdiSpiHelper::createTypeId).collect(joining("String_Node_Str","String_Node_Str","String_Node_Str"));
}
Program: 13139
Project: 13139
Buggy source:
/** 
 * Return the type of this property. Enhanced getter to enforce supported types
 * @return
 */
public String getType(){
  return isConfidential() && type.equals("String_Node_Str") ? "String_Node_Str" : type;
}

Fixed version (ground truth):
/** 
 * Return the type of this property. Enhanced getter to enforce supported types
 * @return
 */
public String getType(){
  return isConfidential() && type.equals("String_Node_Str") ? "String_Node_Str" : type.substring(0,1).toUpperCase() + type.substring(1);
}
Program: 13140
Project: 13140
Buggy source:
private void populateVirtualProperties(final Context context,final Request request,final JsonValue content) throws ForbiddenException, InternalServerErrorException {
  for (  JsonPointer key : Collections.unmodifiableSet(getSchema().getFields().keySet())) {
    SchemaField field=getSchema().getField(key);
    if (field.isVirtual() && (field.isReturnedByDefault() || request.getFields().contains(field))) {
      field.onRetrieve(context,content);
    }
  }
}

Fixed version (ground truth):
private void populateVirtualProperties(final Context context,final Request request,final JsonValue content) throws ForbiddenException, InternalServerErrorException {
  for (  JsonPointer key : Collections.unmodifiableSet(getSchema().getFields().keySet())) {
    SchemaField field=getSchema().getField(key);
    if (field.isVirtual() && (field.isReturnedByDefault() || request.getFields().contains(key))) {
      field.onRetrieve(context,content);
    }
  }
}
Program: 13143
Project: 13143
Buggy source:
@Override public Promise<ResourceResponse,ResourceException> createAsync(Context context,CreateRequest request){
  final EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
  return super.createAsync(context,request).thenAlways(new Runnable(){
    @Override public void run(){
      measure.end();
    }
  }
);
}

Fixed version (ground truth):
@Override public Promise<ResourceResponse,ResourceException> createAsync(Context context,CreateRequest request){
  final EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
  return super.createAsync(context,copyOfCreateRequest(request)).thenAlways(new Runnable(){
    @Override public void run(){
      measure.end();
    }
  }
);
}
Program: 13144
Project: 13144
Buggy source:
@Override public ResourceResponse create(Context context,CreateRequest request) throws ResourceException {
  EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
  try {
    return super.create(context,request);
  }
  finally {
    measure.end();
  }
}

Fixed version (ground truth):
@Override public ResourceResponse create(Context context,CreateRequest request) throws ResourceException {
  EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
  try {
    return super.create(context,copyOfCreateRequest(request));
  }
  finally {
    measure.end();
  }
}
Program: 13146
Project: 13146
Buggy source:
@Override public Promise<ResourceResponse,ResourceException> updateInstance(final Context context,final String resourceId,final UpdateRequest request){
  logger.debug("String_Node_Str","String_Node_Str" + name + "String_Node_Str"+ resourceId+ "String_Node_Str"+ request.getRevision());
  Context managedContext=new ManagedObjectContext(context);
  try {
    JsonValue _new=decrypt(request.getContent());
    ReadRequest readRequest=Requests.newReadRequest(repoId(resourceId));
    for (    JsonPointer pointer : request.getFields()) {
      readRequest.addField(pointer);
    }
    ResourceResponse readResponse=connectionFactory.getConnection().read(managedContext,readRequest);
    ResourceResponse decryptedResponse=decrypt(readResponse);
    ResourceResponse updatedResponse=update(managedContext,request,resourceId,request.getRevision(),decryptedResponse.getContent(),_new);
    activityLogger.log(managedContext,request,"String_Node_Str",managedId(readResponse.getId()).toString(),readResponse.getContent(),updatedResponse.getContent(),Status.SUCCESS);
    return prepareResponse(managedContext,updatedResponse,request.getFields()).asPromise();
  }
 catch (  ResourceException e) {
    return e.asPromise();
  }
catch (  Exception e) {
    return new InternalServerErrorException(e.getMessage(),e).asPromise();
  }
}

Fixed version (ground truth):
@Override public Promise<ResourceResponse,ResourceException> updateInstance(final Context context,final String resourceId,final UpdateRequest request){
  logger.debug("String_Node_Str","String_Node_Str" + name + "String_Node_Str"+ resourceId+ "String_Node_Str"+ request.getRevision());
  Context managedContext=new ManagedObjectContext(context);
  try {
    JsonValue _new=decrypt(request.getContent());
    ReadRequest readRequest=Requests.newReadRequest(repoId(resourceId));
    for (    JsonPointer pointer : request.getFields()) {
      if (pointer.equals(new JsonPointer("String_Node_Str"))) {
        readRequest.addField("String_Node_Str");
      }
 else       if (!pointer.equals(SchemaField.FIELD_ALL_RELATIONSHIPS)) {
        readRequest.addField(pointer);
      }
    }
    ResourceResponse readResponse=connectionFactory.getConnection().read(managedContext,readRequest);
    ResourceResponse decryptedResponse=decrypt(readResponse);
    ResourceResponse updatedResponse=update(managedContext,request,resourceId,request.getRevision(),decryptedResponse.getContent(),_new);
    activityLogger.log(managedContext,request,"String_Node_Str",managedId(readResponse.getId()).toString(),readResponse.getContent(),updatedResponse.getContent(),Status.SUCCESS);
    return prepareResponse(managedContext,updatedResponse,request.getFields()).asPromise();
  }
 catch (  ResourceException e) {
    return e.asPromise();
  }
catch (  Exception e) {
    return new InternalServerErrorException(e.getMessage(),e).asPromise();
  }
}
Program: 13149
Project: 13149
Buggy source:
/** 
 * {@inheritDoc} 
 */
@Override public Promise<JsonValue,ResourceException> clear(final Context context,final String resourceId){
  return getRelationshipValueForResource(context,resourceId).thenAsync(new AsyncFunction<JsonValue,JsonValue,ResourceException>(){
    @Override public Promise<JsonValue,ResourceException> apply(    JsonValue existing) throws ResourceException {
      final List<Promise<ResourceResponse,ResourceException>> deleted=new ArrayList<>();
      for (      JsonValue relationship : existing) {
        final String id=relationship.get(FIELD_ID).asString();
        deleted.add(deleteInstance(context,id,Requests.newDeleteRequest("String_Node_Str")));
      }
      return when(deleted).then(new Function<List<ResourceResponse>,JsonValue,ResourceException>(){
        @Override public JsonValue apply(        List<ResourceResponse> resourceResponses) throws ResourceException {
          final JsonValue deleted=json(array());
          for (          ResourceResponse resourceResponse : resourceResponses) {
            deleted.add(resourceResponse.getContent());
          }
          return deleted;
        }
      }
);
    }
  }
);
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
@Override public Promise<JsonValue,ResourceException> clear(final Context context,final String resourceId){
  return getRelationshipValueForResource(context,resourceId).thenAsync(new AsyncFunction<JsonValue,JsonValue,ResourceException>(){
    @Override public Promise<JsonValue,ResourceException> apply(    JsonValue existing) throws ResourceException {
      final List<Promise<ResourceResponse,ResourceException>> deleted=new ArrayList<>();
      for (      JsonValue relationship : existing) {
        final String id=relationship.get(FIELD_ID).asString();
        DeleteRequest deleteRequest=Requests.newDeleteRequest("String_Node_Str");
        deleteRequest.setAdditionalParameter(PARAM_MANAGED_OBJECT_ID,resourceId);
        deleted.add(deleteInstance(context,id,deleteRequest));
      }
      return when(deleted).then(new Function<List<ResourceResponse>,JsonValue,ResourceException>(){
        @Override public JsonValue apply(        List<ResourceResponse> resourceResponses) throws ResourceException {
          final JsonValue deleted=json(array());
          for (          ResourceResponse resourceResponse : resourceResponses) {
            deleted.add(resourceResponse.getContent());
          }
          return deleted;
        }
      }
);
    }
  }
);
}
Program: 13151
Project: 13151
Buggy source:
/** 
 * Reads and returns the managed object associated with the specified context.
 * @param context the {@link Context} object.
 * @return the managed object.
 * @throws ResourceException if an error was encountered while reading the managed object.
 */
protected ResourceResponse getManagedObject(Context context) throws ResourceException {
  String managedObjectPath=resourcePath.child(getManagedObjectId(context)).toString();
  return getConnection().read(context,Requests.newReadRequest(managedObjectPath));
}

Fixed version (ground truth):
/** 
 * Reads and returns the managed object associated with the specified context.
 * @param context the {@link Context} object.
 * @return the managed object.
 * @throws ResourceException if an error was encountered while reading the managed object.
 */
protected ResourceResponse getManagedObject(Context context) throws ResourceException {
  String managedObjectPath=resourceContainer.child(getManagedObjectId(context)).toString();
  return getConnection().read(context,Requests.newReadRequest(managedObjectPath));
}
Program: 13152
Project: 13152
Buggy source:
/** 
 * Create a new relationship set for the given managed resource
 * @param connectionFactory Connection factory used to access the repository
 * @param resourcePath Name of the resource we are handling relationships for eg. managed/user
 * @param propertyName Name of property on first object represents the relationship
 * @param isReverse Whether or not this relationship is isReverse
 */
protected RelationshipProvider(final ConnectionFactory connectionFactory,final ResourcePath resourcePath,final JsonPointer propertyName,final JsonPointer reversePropertyName,final boolean isReverse,ActivityLogger activityLogger,final ManagedObjectSyncService managedObjectSyncService){
  this.connectionFactory=connectionFactory;
  this.resourcePath=resourcePath;
  this.propertyName=propertyName;
  this.reversePropertyName=reversePropertyName;
  this.isRevereseRelationship=isReverse;
  this.activityLogger=activityLogger;
  this.managedObjectSyncService=managedObjectSyncService;
}

Fixed version (ground truth):
/** 
 * Create a new relationship set for the given managed resource
 * @param connectionFactory Connection factory used to access the repository
 * @param resourcePath Name of the resource we are handling relationships for eg. managed/user
 * @param propertyName Name of property on first object represents the relationship
 * @param isReverse Whether or not this relationship is isReverse
 */
protected RelationshipProvider(final ConnectionFactory connectionFactory,final ResourcePath resourcePath,final JsonPointer propertyName,final JsonPointer reversePropertyName,final boolean isReverse,ActivityLogger activityLogger,final ManagedObjectSyncService managedObjectSyncService){
  this.connectionFactory=connectionFactory;
  this.resourceContainer=resourcePath;
  this.propertyName=propertyName;
  this.reversePropertyName=reversePropertyName;
  this.isReverseRelationship=isReverse;
  this.activityLogger=activityLogger;
  this.managedObjectSyncService=managedObjectSyncService;
}
Program: 13153
Project: 13153
Buggy source:
/** 
 * Returns the managed object's full path corresponding to the passed in   {@link Context}.
 * @param context the {@link Context} object.
 * @return a String representing the managed object's ID.
 */
protected String getManagedObjectPath(Context context){
  return resourcePath.child(getManagedObjectId(context)).toString();
}

Fixed version (ground truth):
/** 
 * Returns the managed object's full path corresponding to the passed in   {@link Context}.
 * @param context the {@link Context} object.
 * @return a String representing the managed object's ID.
 */
protected String getManagedObjectPath(Context context){
  return resourceContainer.child(getManagedObjectId(context)).toString();
}
Program: 13155
Project: 13155
Buggy source:
/** 
 * Returns the path of the first resource in this relationship using the firstId parameter from either the URI or  the Request. If firstId is not found in the URI context then the request parameter is used.
 * @param context Context containing a {@link UriRouterContext} to check for template variables
 * @param request Request containing a fall-back firstId parameter
 * @see #resourcePath
 * @return The resource path of the first resource as a child of resourcePath
 */
protected final ResourcePath firstResourcePath(final Context context,final Request request) throws BadRequestException {
  final String uriFirstId=context.asContext(UriRouterContext.class).getUriTemplateVariables().get(PARAM_MANAGED_OBJECT_ID);
  final String firstId=uriFirstId != null ? uriFirstId : request.getAdditionalParameter(PARAM_MANAGED_OBJECT_ID);
  if (StringUtils.isNotBlank(firstId)) {
    return resourcePath.child(firstId);
  }
 else {
    throw new BadRequestException("String_Node_Str" + PARAM_MANAGED_OBJECT_ID + "String_Node_Str"+ PARAM_MANAGED_OBJECT_ID+ "String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * Returns the path of the first resource in this relationship using the firstId parameter from either the URI or  the Request. If firstId is not found in the URI context then the request parameter is used.
 * @param context Context containing a {@link UriRouterContext} to check for template variables
 * @param request Request containing a fall-back firstId parameter
 * @see #resourceContainer
 * @return The resource path of the first resource as a child of resourcePath
 */
protected final ResourcePath firstResourcePath(final Context context,final Request request) throws BadRequestException {
  final String uriFirstId=context.asContext(UriRouterContext.class).getUriTemplateVariables().get(PARAM_MANAGED_OBJECT_ID);
  final String firstId=uriFirstId != null ? uriFirstId : request.getAdditionalParameter(PARAM_MANAGED_OBJECT_ID);
  if (StringUtils.isNotBlank(firstId)) {
    return resourceContainer.child(firstId);
  }
 else {
    throw new BadRequestException("String_Node_Str" + PARAM_MANAGED_OBJECT_ID + "String_Node_Str"+ PARAM_MANAGED_OBJECT_ID+ "String_Node_Str");
  }
}
Program: 13157
Project: 13157
Buggy source:
/** 
 * Queries relationships, returning the relationship associated with this providers resource path and the specified  relationship field.
 * @param context The current context
 * @param managedObjectId The id of the managed object to find relationships associated with
 * @return
 */
private Promise<ResourceResponse,ResourceException> queryRelationship(final Context context,final String managedObjectId){
  try {
    final QueryRequest queryRequest=Requests.newQueryRequest(REPO_RESOURCE_PATH);
    final List<ResourceResponse> relationships=new ArrayList<>();
    queryRequest.setQueryFilter(QueryFilter.and(QueryFilter.equalTo(new JsonPointer(isRevereseRelationship ? REPO_FIELD_SECOND_ID : REPO_FIELD_FIRST_ID),resourcePath.child(managedObjectId)),QueryFilter.equalTo(new JsonPointer(REPO_FIELD_FIRST_PROPERTY_NAME),propertyName)));
    connectionFactory.getConnection().query(context,queryRequest,relationships);
    if (relationships.isEmpty()) {
      return new NotFoundException().asPromise();
    }
 else {
      return newResultPromise(formatResponse(context,null).apply(relationships.get(0)));
    }
  }
 catch (  ResourceException e) {
    return e.asPromise();
  }
}

Fixed version (ground truth):
/** 
 * Queries relationships, returning the relationship associated with this providers resource path and the specified  relationship field.
 * @param context The current context
 * @param managedObjectId The id of the managed object to find relationships associated with
 * @return
 */
private Promise<ResourceResponse,ResourceException> queryRelationship(final Context context,final String managedObjectId){
  try {
    final QueryRequest queryRequest=Requests.newQueryRequest(REPO_RESOURCE_PATH);
    final List<ResourceResponse> relationships=new ArrayList<>();
    queryRequest.setQueryFilter(QueryFilter.and(QueryFilter.equalTo(new JsonPointer(isReverseRelationship ? REPO_FIELD_SECOND_ID : REPO_FIELD_FIRST_ID),resourceContainer.child(managedObjectId)),QueryFilter.equalTo(new JsonPointer(REPO_FIELD_FIRST_PROPERTY_NAME),propertyName)));
    connectionFactory.getConnection().query(context,queryRequest,relationships);
    if (relationships.isEmpty()) {
      return new NotFoundException().asPromise();
    }
 else {
      return newResultPromise(formatResponse(context,null).apply(relationships.get(0)));
    }
  }
 catch (  ResourceException e) {
    return e.asPromise();
  }
}
Program: 13161
Project: 13161
Buggy source:
static QueryFilter<JsonPointer> asRelationshipQueryFilter(QueryFilter<JsonPointer> filter){
  return filter.accept(VISITOR,null);
}

Fixed version (ground truth):
static QueryFilter<JsonPointer> asRelationshipQueryFilter(Boolean isReverse,QueryFilter<JsonPointer> filter){
  return filter.accept(VISITOR,isReverse);
}
Program: 13162
Project: 13162
Buggy source:
/** 
 * Visits each   {@link QueryFilter} in a list of filters and returns a list of thevisited filters.
 * @param subFilters a list of the filters to visit
 * @return a list of visited filters
 */
private List<QueryFilter<JsonPointer>> visitQueryFilters(List<QueryFilter<JsonPointer>> subFilters){
  List<QueryFilter<JsonPointer>> visitedFilters=new ArrayList<>();
  for (  QueryFilter<JsonPointer> filter : subFilters) {
    visitedFilters.add(asRelationshipQueryFilter(filter));
  }
  return visitedFilters;
}

Fixed version (ground truth):
/** 
 * Visits each   {@link QueryFilter} in a list of filters and returns a list of thevisited filters.
 * @param subFilters a list of the filters to visit
 * @return a list of visited filters
 */
private List<QueryFilter<JsonPointer>> visitQueryFilters(Boolean isReverse,List<QueryFilter<JsonPointer>> subFilters){
  List<QueryFilter<JsonPointer>> visitedFilters=new ArrayList<>();
  for (  QueryFilter<JsonPointer> filter : subFilters) {
    visitedFilters.add(asRelationshipQueryFilter(isReverse,filter));
  }
  return visitedFilters;
}
Program: 13164
Project: 13164
Buggy source:
@Override public QueryFilter<JsonPointer> visitOrFilter(Boolean isReverse,List<QueryFilter<JsonPointer>> subFilters){
  return QueryFilter.or(visitQueryFilters(subFilters));
}

Fixed version (ground truth):
@Override public QueryFilter<JsonPointer> visitOrFilter(Boolean isReverse,List<QueryFilter<JsonPointer>> subFilters){
  return QueryFilter.or(visitQueryFilters(isReverse,subFilters));
}
Program: 13165
Project: 13165
Buggy source:
@Override public QueryFilter<JsonPointer> visitAndFilter(Boolean isReverse,List<QueryFilter<JsonPointer>> subFilters){
  return QueryFilter.and(visitQueryFilters(subFilters));
}

Fixed version (ground truth):
@Override public QueryFilter<JsonPointer> visitAndFilter(Boolean isReverse,List<QueryFilter<JsonPointer>> subFilters){
  return QueryFilter.and(visitQueryFilters(isReverse,subFilters));
}
Program: 13167
Project: 13167
Buggy source:
@Override public void frameworkEvent(FrameworkEvent event){
  logger.debug("String_Node_Str",event.getType(),event.toString());
  if (event.getType() == FrameworkEvent.STARTED) {
    logger.debug("String_Node_Str");
    frameworkStarted=true;
  }
  if (frameworkStarted) {
switch (event.getType()) {
case FrameworkEvent.PACKAGES_REFRESHED:
case FrameworkEvent.STARTLEVEL_CHANGED:
case FrameworkEvent.WARNING:
case FrameworkEvent.INFO:
      break;
default :
    checkState();
}
}
if (event.getType() == FrameworkEvent.STARTED) {
if (!stateDetail.state.equals(AppState.ACTIVE_READY)) {
  scheduleCheckStartup();
}
}
}

Fixed version (ground truth):
@Override public void frameworkEvent(FrameworkEvent event){
  final int eventType=event.getType();
  logger.debug("String_Node_Str",eventType,event.toString());
  frameworkStatusService.setFrameworkStatus(eventType);
  if (eventType == FrameworkEvent.STARTED) {
    logger.debug("String_Node_Str");
    frameworkStarted=true;
  }
  if (frameworkStarted) {
switch (eventType) {
case FrameworkEvent.PACKAGES_REFRESHED:
case FrameworkEvent.STARTLEVEL_CHANGED:
case FrameworkEvent.WARNING:
case FrameworkEvent.INFO:
      break;
default :
    checkState();
}
}
if (eventType == FrameworkEvent.STARTED) {
if (!stateDetail.state.equals(AppState.ACTIVE_READY)) {
  scheduleCheckStartup(serviceStartMax);
}
}
}
Program: 13168
Project: 13168
Buggy source:
@Deactivate protected void deactivate(ComponentContext context){
  if (scheduledExecutor != null) {
    scheduledExecutor.shutdown();
  }
  if (frameworkListener != null) {
    context.getBundleContext().removeFrameworkListener(frameworkListener);
  }
  if (svcListener != null) {
    context.getBundleContext().removeServiceListener(svcListener);
  }
  if (bundleListener != null) {
    context.getBundleContext().removeBundleListener(bundleListener);
  }
  frameworkStarted=false;
  setState(AppState.STOPPING,"String_Node_Str");
  logger.info("String_Node_Str");
}

Fixed version (ground truth):
@Deactivate protected void deactivate(ComponentContext context){
  if (scheduledExecutor != null) {
    scheduledExecutor.shutdown();
  }
  if (frameworkListener != null) {
    context.getBundleContext().removeFrameworkListener(frameworkListener);
  }
  if (svcListener != null) {
    context.getBundleContext().removeServiceListener(svcListener);
  }
  if (bundleListener != null) {
    context.getBundleContext().removeBundleListener(bundleListener);
  }
  if (tracker != null) {
    tracker.close();
    tracker=null;
  }
  frameworkStarted=false;
  setState(AppState.STOPPING,"String_Node_Str");
  logger.info("String_Node_Str");
}
Program: 13169
Project: 13169
Buggy source:
@Override public void addedService(ServiceReference reference,Object service){
  ClusterManagementService clusterService=(ClusterManagementService)service;
  if (clusterService != null) {
    clusterService.register(LISTENER_ID,this);
    clusterEnabled=clusterService.isEnabled();
    cluster=clusterService;
  }
}

Fixed version (ground truth):
@Override public void addedService(ServiceReference reference,Object service){
  ClusterManagementService clusterService=(ClusterManagementService)service;
  if (clusterService != null) {
    clusterService.register(LISTENER_ID,this);
    clusterEnabled=clusterService.isEnabled();
    cluster=clusterService;
    if (clusterEnabled && !cluster.isStarted()) {
      cluster.startClusterManagement();
    }
  }
}
Program: 13171
Project: 13171
Buggy source:
/** 
 * After the timeout period passes past framework start event, check that the required services are present. If not, report startup error
 */
private void scheduleCheckStartup(){
  Runnable command=new Runnable(){
    @Override public void run(){
      appStarting=false;
      checkState();
      if (!stateDetail.state.equals(AppState.ACTIVE_READY)) {
        logger.error("String_Node_Str",stateDetail.state,stateDetail.shortDesc);
      }
 else {
        logger.debug("String_Node_Str");
      }
    }
  }
;
  if (scheduledExecutor.isShutdown()) {
    scheduledExecutor=Executors.newSingleThreadScheduledExecutor();
  }
  scheduledExecutor.schedule(command,serviceStartMax,TimeUnit.MILLISECONDS);
}

Fixed version (ground truth):
/** 
 * After the timeout period passes past framework start event, check that the required services are present. If not, report startup error
 * @param delay a delay in milliseconds before checking the state.
 */
private void scheduleCheckStartup(long delay){
  Runnable command=new Runnable(){
    @Override public void run(){
      appStarting=false;
      checkState();
      if (!stateDetail.state.equals(AppState.ACTIVE_READY)) {
        logger.error("String_Node_Str",stateDetail.state,stateDetail.shortDesc);
      }
 else {
        logger.debug("String_Node_Str");
      }
    }
  }
;
  if (scheduledExecutor.isShutdown()) {
    scheduledExecutor=Executors.newSingleThreadScheduledExecutor();
  }
  scheduledExecutor.schedule(command,delay,TimeUnit.MILLISECONDS);
}
Program: 13173
Project: 13173
Buggy source:
@Test public void testListCurrentlyExecutingJobsAction() throws Exception {
  final ActionRequest readRequest=Requests.newActionRequest("String_Node_Str",SchedulerService.ACTION_LIST_CURRENTLY_EXECUTING_JOBS);
  Promise<ActionResponse,ResourceException> promise=schedulerService.handleAction(new RootContext(),readRequest);
  AssertJPromiseAssert.assertThat(promise).isNotNull().succeeded();
  ActionResponse resourceResponse=promise.getOrThrow();
  assertThat(resourceResponse.getJsonContent().asList().size()).isEqualTo(0);
}

Fixed version (ground truth):
@Test public void testListCurrentlyExecutingJobsAction() throws Exception {
  final ActionRequest readRequest=Requests.newActionRequest("String_Node_Str",SchedulerAction.listCurrentlyExecutingJobs.toString());
  Promise<ActionResponse,ResourceException> promise=schedulerService.handleAction(new RootContext(),readRequest);
  AssertJPromiseAssert.assertThat(promise).isNotNull().succeeded();
  ActionResponse resourceResponse=promise.getOrThrow();
  assertThat(resourceResponse.getJsonContent().asList().size()).isEqualTo(0);
}
Program: 13174
Project: 13174
Buggy source:
@Test public void testPauseJobsAction() throws Exception {
  final ActionRequest readRequest=Requests.newActionRequest("String_Node_Str",SchedulerService.ACTION_PAUSE_JOBS);
  Promise<ActionResponse,ResourceException> promise=schedulerService.handleAction(new RootContext(),readRequest);
  AssertJPromiseAssert.assertThat(promise).isNotNull().succeeded();
  ActionResponse resourceResponse=promise.getOrThrow();
  assertThat(resourceResponse.getJsonContent().get("String_Node_Str").getObject()).isEqualTo(new Boolean(true));
}

Fixed version (ground truth):
@Test public void testPauseJobsAction() throws Exception {
  final ActionRequest readRequest=Requests.newActionRequest("String_Node_Str",SchedulerAction.pauseJobs.toString());
  Promise<ActionResponse,ResourceException> promise=schedulerService.handleAction(new RootContext(),readRequest);
  AssertJPromiseAssert.assertThat(promise).isNotNull().succeeded();
  ActionResponse resourceResponse=promise.getOrThrow();
  assertThat(resourceResponse.getJsonContent().get("String_Node_Str").getObject()).isEqualTo(new Boolean(true));
}
Program: 13175
Project: 13175
Buggy source:
@Test public void testResumeJobsAction() throws Exception {
  final ActionRequest readRequest=Requests.newActionRequest("String_Node_Str",SchedulerService.ACTION_RESUME_JOBS);
  Promise<ActionResponse,ResourceException> promise=schedulerService.handleAction(new RootContext(),readRequest);
  AssertJPromiseAssert.assertThat(promise).isNotNull().succeeded();
  ActionResponse resourceResponse=promise.getOrThrow();
  assertThat(resourceResponse.getJsonContent().get("String_Node_Str").getObject()).isEqualTo(new Boolean(true));
}

Fixed version (ground truth):
@Test public void testResumeJobsAction() throws Exception {
  final ActionRequest readRequest=Requests.newActionRequest("String_Node_Str",SchedulerAction.resumeJobs.toString());
  Promise<ActionResponse,ResourceException> promise=schedulerService.handleAction(new RootContext(),readRequest);
  AssertJPromiseAssert.assertThat(promise).isNotNull().succeeded();
  ActionResponse resourceResponse=promise.getOrThrow();
  assertThat(resourceResponse.getJsonContent().get("String_Node_Str").getObject()).isEqualTo(new Boolean(true));
}
Program: 13177
Project: 13177
Buggy source:
/** 
 * Returns a deep copy of the supplied   {@link JsonValue}. Used to remove special relation fields before persisting the value to the repository.
 * @param value The JsonValue map to strip relationship fields from
 * @return A deep copy of the JsonValue value with relationship fields removed
 */
protected JsonValue stripRelationshipFields(JsonValue value){
  final JsonValue stripped=value.copy();
  for (  JsonPointer field : schema.getRelationshipFields()) {
    stripped.remove(field);
  }
  return stripped;
}

Fixed version (ground truth):
/** 
 * Removes all relationship fields from the supplied   {@link JsonValue} instance of a managed object.  Returns a {@link JsonValue} object containing the stripped fields.
 * @param value The JsonValue map to strip relationship fields from
 * @return A {@link JsonValue} object containing the stripped fields.
 */
protected JsonValue stripRelationshipFields(JsonValue value){
  final JsonValue stripped=json(object());
  for (  JsonPointer field : schema.getRelationshipFields()) {
    JsonValue fieldValue=value.get(field);
    stripped.put(field,fieldValue != null ? fieldValue.getObject() : null);
    value.remove(field);
  }
  return stripped;
}
Program: 13179
Project: 13179
Buggy source:
/** 
 * Converts relationship client object pointers to repo format. Converts /_refProperties/_id to /_id Converts /_refProperties/_rev to /_rev Converts /_ref to /secondId Converts /_refProperties/... to /properties/...
 * @param field a {@link JsonPointer} representing the field to modify.
 * @return a {@link JsonPointer} representing the modified field
 */
private JsonPointer getRelationshipPointer(JsonPointer field){
  if (FIELD_ID.equals(field)) {
    return new JsonPointer(FIELD_CONTENT_ID);
  }
  if (FIELD_REV.equals(field)) {
    return new JsonPointer(FIELD_CONTENT_REVISION);
  }
  if (FIELD_REFERENCE.equals(field.toString())) {
    return new JsonPointer(REPO_FIELD_SECOND_ID);
  }
  if (FIELD_PROPERTIES.leaf().equals(field.get(0))) {
    JsonPointer ptr=new JsonPointer(REPO_FIELD_PROPERTIES);
    for (    String s : field.relativePointer(field.size() - 1)) {
      ptr=ptr.child(s);
    }
    return ptr;
  }
  return field;
}

Fixed version (ground truth):
/** 
 * Converts relationship client object pointers to repo format. Converts /_refProperties/_id to /_id Converts /_refProperties/_rev to /_rev Converts /_ref to /secondId Converts /_refProperties/... to /properties/...
 * @param field a {@link JsonPointer} representing the field to modify.
 * @return a {@link JsonPointer} representing the modified field
 */
private JsonPointer getRelationshipPointer(JsonPointer field){
  if (FIELD_ID.equals(field)) {
    return new JsonPointer(FIELD_CONTENT_ID);
  }
  if (FIELD_REV.equals(field)) {
    return new JsonPointer(FIELD_CONTENT_REVISION);
  }
  if (FIELD_REFERENCE.equals(field)) {
    return new JsonPointer(REPO_FIELD_SECOND_ID);
  }
  if (FIELD_PROPERTIES.leaf().equals(field.get(0))) {
    JsonPointer ptr=new JsonPointer(REPO_FIELD_PROPERTIES);
    for (    String s : field.relativePointer(field.size() - 1)) {
      ptr=ptr.child(s);
    }
    return ptr;
  }
  return field;
}
Program: 13180
Project: 13180
Buggy source:
public JsonValue mapToJsonValue(ResultSet rs,Set<String> columnNames) throws SQLException, InternalServerErrorException {
  JsonValue mappedResult=new JsonValue(new LinkedHashMap<String,Object>());
  for (  ColumnMapping entry : columnMappings) {
    Object value=null;
    if (columnNames.contains(entry.dbColName)) {
      if (ColumnMapping.TYPE_STRING.equals(entry.dbColType)) {
        value=rs.getString(entry.dbColName);
        if (cryptoServiceAccessor == null || cryptoServiceAccessor.access() == null) {
          throw new InternalServerErrorException("String_Node_Str");
        }
        if (JsonUtil.isEncrypted((String)value)) {
          value=convertToJson(entry.dbColName,"String_Node_Str",(String)value,Map.class).asMap();
        }
      }
 else       if (ColumnMapping.TYPE_JSON_MAP.equals(entry.dbColType)) {
        value=convertToJson(entry.dbColName,entry.dbColType,rs.getString(entry.dbColName),Map.class).asMap();
      }
 else       if (ColumnMapping.TYPE_JSON_LIST.equals(entry.dbColType)) {
        value=convertToJson(entry.dbColName,entry.dbColType,rs.getString(entry.dbColName),List.class).asList();
      }
 else {
        throw new InternalServerErrorException("String_Node_Str" + entry.dbColType);
      }
      mappedResult.put(entry.objectColPointer,value);
    }
  }
  logger.debug("String_Node_Str",rs,mappedResult);
  return mappedResult;
}

Fixed version (ground truth):
public JsonValue mapToJsonValue(ResultSet rs,Set<String> columnNames) throws SQLException, InternalServerErrorException {
  JsonValue mappedResult=new JsonValue(new LinkedHashMap<String,Object>());
  for (  ColumnMapping entry : columnMappings) {
    Object value=null;
    if (columnNames.contains(entry.dbColName)) {
      if (ColumnMapping.TYPE_STRING.equals(entry.dbColType)) {
        value=rs.getString(entry.dbColName);
        if (cryptoServiceAccessor == null || cryptoServiceAccessor.access() == null) {
          throw new InternalServerErrorException("String_Node_Str");
        }
        if (JsonUtil.isEncrypted((String)value)) {
          value=convertToJson(entry.dbColName,"String_Node_Str",(String)value,Map.class).asMap();
        }
      }
 else       if (ColumnMapping.TYPE_JSON_MAP.equals(entry.dbColType)) {
        value=convertToJson(entry.dbColName,entry.dbColType,rs.getString(entry.dbColName),Map.class).asMap();
      }
 else       if (ColumnMapping.TYPE_JSON_LIST.equals(entry.dbColType)) {
        value=convertToJson(entry.dbColName,entry.dbColType,rs.getString(entry.dbColName),List.class).asList();
      }
 else {
        throw new InternalServerErrorException("String_Node_Str" + entry.dbColType);
      }
      mappedResult.putPermissive(entry.objectColPointer,value);
    }
  }
  logger.debug("String_Node_Str",rs,mappedResult);
  return mappedResult;
}
Program: 13181
Project: 13181
Buggy source:
@Activate protected void activate(ComponentContext context) throws ServletException, NamespaceException {
  logger.debug("String_Node_Str",SERVLET_ALIAS);
  servlet=new HttpFrameworkServlet(new HttpApplication(){
    @Override public Handler start() throws HttpApplicationException {
      return CrestHttp.newHttpHandler(connectionFactory,new IDMSecurityContextFactory(augmentSecurityScripts));
    }
    @Override public Factory<Buffer> getBufferFactory(){
      return null;
    }
    @Override public void stop(){
    }
  }
);
  servletRegistration.registerServlet(SERVLET_ALIAS,servlet,new Hashtable());
  logger.info("String_Node_Str",SERVLET_ALIAS);
}

Fixed version (ground truth):
@Activate protected void activate(ComponentContext context) throws ServletException, NamespaceException {
  logger.debug("String_Node_Str",SERVLET_ALIAS);
  final Handler handler=CrestHttp.newHttpHandler(connectionFactory,new IDMSecurityContextFactory(augmentSecurityScripts));
  servlet=new HttpFrameworkServlet(new HttpApplication(){
    @Override public Handler start() throws HttpApplicationException {
      return handler;
    }
    @Override public Factory<Buffer> getBufferFactory(){
      return null;
    }
    @Override public void stop(){
    }
  }
);
  servletRegistration.registerServlet(SERVLET_ALIAS,servlet,new Hashtable());
  logger.info("String_Node_Str",SERVLET_ALIAS);
}
Program: 13182
Project: 13182
Buggy source:
@Override public Handler start() throws HttpApplicationException {
  return CrestHttp.newHttpHandler(connectionFactory,new IDMSecurityContextFactory(augmentSecurityScripts));
}

Fixed version (ground truth):
@Override public Handler start() throws HttpApplicationException {
  return handler;
}