Program: 13150
Project: 13150
Buggy source:
/** 
 * Clear all relationships not present in   {@code relationshipsToKeep}.
 * @param context The current context.
 * @param resourceId The resource whose relationships we wish to clear
 * @param relationshipsToKeep Set of relationship ids that should not be deleted
 * @return A promised JsonValue array of delete responses
 */
private Promise<JsonValue,ResourceException> clearNotIn(final Context context,final String resourceId,final Set<String> relationshipsToKeep){
  return getRelationshipValueForResource(context,resourceId).thenAsync(new AsyncFunction<JsonValue,JsonValue,ResourceException>(){
    @Override public Promise<JsonValue,ResourceException> apply(    JsonValue existingRelationships) throws ResourceException {
      final List<Promise<ResourceResponse,ResourceException>> promises=new ArrayList<>();
      for (      JsonValue relationship : existingRelationships) {
        final String id=relationship.get(FIELD_ID).asString();
        if (!relationshipsToKeep.contains(id)) {
          final DeleteRequest deleteRequest=Requests.newDeleteRequest("String_Node_Str",id);
          promises.add(deleteInstance(context,id,deleteRequest));
        }
      }
      return when(promises).then(new Function<List<ResourceResponse>,JsonValue,ResourceException>(){
        @Override public JsonValue apply(        List<ResourceResponse> resourceResponses) throws ResourceException {
          final JsonValue result=json(array());
          for (          ResourceResponse resourceResponse : resourceResponses) {
            result.add(resourceResponse.getContent());
          }
          return result;
        }
      }
);
    }
  }
);
}

Fixed version (ground truth):
/** 
 * Clear all relationships not present in   {@code relationshipsToKeep}.
 * @param context The current context.
 * @param resourceId The resource whose relationships we wish to clear
 * @param relationshipsToKeep Set of relationship ids that should not be deleted
 * @return A promised JsonValue array of delete responses
 */
private Promise<JsonValue,ResourceException> clearNotIn(final Context context,final String resourceId,final Set<String> relationshipsToKeep){
  return getRelationshipValueForResource(context,resourceId).thenAsync(new AsyncFunction<JsonValue,JsonValue,ResourceException>(){
    @Override public Promise<JsonValue,ResourceException> apply(    JsonValue existingRelationships) throws ResourceException {
      final List<Promise<ResourceResponse,ResourceException>> promises=new ArrayList<>();
      for (      JsonValue relationship : existingRelationships) {
        final String id=relationship.get(FIELD_ID).asString();
        if (!relationshipsToKeep.contains(id)) {
          final DeleteRequest deleteRequest=Requests.newDeleteRequest("String_Node_Str",id);
          deleteRequest.setAdditionalParameter(PARAM_MANAGED_OBJECT_ID,resourceId);
          promises.add(deleteInstance(context,id,deleteRequest));
        }
      }
      return when(promises).then(new Function<List<ResourceResponse>,JsonValue,ResourceException>(){
        @Override public JsonValue apply(        List<ResourceResponse> resourceResponses) throws ResourceException {
          final JsonValue result=json(array());
          for (          ResourceResponse resourceResponse : resourceResponses) {
            result.add(resourceResponse.getContent());
          }
          return result;
        }
      }
);
    }
  }
);
}