Program: 49210
Project: 49210
Buggy source:
/** 
 * Revokes the given set of entitlements.
 * @param entsToRevoke entitlements to revoke
 * @param alreadyDeletedPools pools to skip deletion as they have already been deleted
 * @param regenCertsAndStatuses if this revocation should also trigger regeneration of certificatesand recomputation of statuses. For performance reasons some callers might choose to set this to false.
 */
@Transactional @Traceable public void revokeEntitlements(List<Entitlement> entsToRevoke,Set<String> alreadyDeletedPools,boolean regenCertsAndStatuses){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str",getEntIds(entsToRevoke));
  }
  if (CollectionUtils.isEmpty(entsToRevoke)) {
    return;
  }
  List<Pool> poolsToDelete=poolCurator.listBySourceEntitlements(entsToRevoke);
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str",getPoolIds(poolsToDelete));
  }
  List<Pool> poolsToLock=new ArrayList<Pool>();
  poolsToLock.addAll(poolsToDelete);
  for (  Entitlement ent : entsToRevoke) {
    poolsToLock.add(ent.getPool());
    if (ent.getPool() != null && ent.getPool().isDevelopmentPool()) {
      poolsToDelete.add(ent.getPool());
    }
  }
  poolCurator.lockAndLoad(poolsToLock);
  log.info("String_Node_Str",entsToRevoke.size());
  entsToRevoke=new ArrayList<Entitlement>(entsToRevoke);
  for (  Pool pool : poolsToDelete) {
    for (    Entitlement ent : pool.getEntitlements()) {
      ent.setDeletedFromPool(true);
      entsToRevoke.add(ent);
    }
  }
  log.debug("String_Node_Str");
  List<Pool> poolsToSave=new ArrayList<Pool>();
  for (  Entitlement ent : entsToRevoke) {
    Pool pool=ent.getPool();
    int entQuantity=ent.getQuantity() != null ? ent.getQuantity() : 0;
    pool.setConsumed(pool.getConsumed() - entQuantity);
    Consumer consumer=ent.getConsumer();
    if (consumer.isManifestDistributor()) {
      pool.setExported(pool.getExported() - entQuantity);
    }
 else     if (consumer.isShare()) {
      pool.setShared(pool.getShared() - entQuantity);
    }
    consumer.setEntitlementCount(consumer.getEntitlementCount() - entQuantity);
    consumerCurator.update(consumer);
    poolsToSave.add(pool);
  }
  poolCurator.updateAll(poolsToSave,false,false);
  if (regenCertsAndStatuses) {
    log.debug("String_Node_Str");
    int update=this.entitlementCurator.markDependentEntitlementsDirty(entsToRevoke);
    log.debug("String_Node_Str",update);
  }
  log.info("String_Node_Str");
  poolCurator.batchDelete(poolsToDelete,alreadyDeletedPools);
  log.info("String_Node_Str");
  entitlementCurator.batchDelete(entsToRevoke);
  log.info("String_Node_Str");
  entitlementCurator.flush();
  log.info("String_Node_Str");
  Map<Consumer,List<Entitlement>> consumerSortedEntitlements=entitlementCurator.getDistinctConsumers(entsToRevoke);
  filterAndUpdateStackingEntitlements(consumerSortedEntitlements,alreadyDeletedPools);
  for (  Entitlement ent : entsToRevoke) {
    enforcer.postUnbind(ent.getConsumer(),this,ent);
  }
  if (!regenCertsAndStatuses) {
    log.info("String_Node_Str");
    sendDeletedEvents(entsToRevoke);
    return;
  }
  log.info("String_Node_Str",consumerSortedEntitlements.size());
  int i=1;
  for (  Consumer consumer : consumerSortedEntitlements.keySet()) {
    if (i++ % 1000 == 0) {
      consumerCurator.flush();
    }
    complianceRules.getStatus(consumer);
  }
  consumerCurator.flush();
  log.info("String_Node_Str");
  sendDeletedEvents(entsToRevoke);
}

Fixed version (ground truth):
/** 
 * Revokes the given set of entitlements.
 * @param entsToRevoke entitlements to revoke
 * @param alreadyDeletedPools pools to skip deletion as they have already been deleted
 * @param regenCertsAndStatuses if this revocation should also trigger regeneration of certificatesand recomputation of statuses. For performance reasons some callers might choose to set this to false.
 */
@Transactional @Traceable public void revokeEntitlements(List<Entitlement> entsToRevoke,Set<String> alreadyDeletedPools,boolean regenCertsAndStatuses){
  if (CollectionUtils.isEmpty(entsToRevoke)) {
    return;
  }
  log.debug("String_Node_Str",entsToRevoke.size());
  if (log.isTraceEnabled()) {
    log.trace("String_Node_Str",getEntIds(entsToRevoke));
  }
  Set<Pool> poolsToDelete=this.poolCurator.listBySourceEntitlements(entsToRevoke);
  log.debug("String_Node_Str",poolsToDelete.size());
  if (log.isTraceEnabled()) {
    log.trace("String_Node_Str",getPoolIds(poolsToDelete));
  }
  List<Pool> poolsToLock=new ArrayList<Pool>();
  poolsToLock.addAll(poolsToDelete);
  for (  Entitlement ent : entsToRevoke) {
    poolsToLock.add(ent.getPool());
    if (ent.getPool() != null && ent.getPool().isDevelopmentPool()) {
      poolsToDelete.add(ent.getPool());
    }
  }
  poolCurator.lockAndLoad(poolsToLock);
  log.info("String_Node_Str",entsToRevoke.size());
  entsToRevoke=new ArrayList<Entitlement>(entsToRevoke);
  for (  Pool pool : poolsToDelete) {
    for (    Entitlement ent : pool.getEntitlements()) {
      ent.setDeletedFromPool(true);
      entsToRevoke.add(ent);
    }
  }
  log.debug("String_Node_Str");
  List<Pool> poolsToSave=new ArrayList<Pool>();
  for (  Entitlement ent : entsToRevoke) {
    Pool pool=ent.getPool();
    int entQuantity=ent.getQuantity() != null ? ent.getQuantity() : 0;
    pool.setConsumed(pool.getConsumed() - entQuantity);
    Consumer consumer=ent.getConsumer();
    if (consumer.isManifestDistributor()) {
      pool.setExported(pool.getExported() - entQuantity);
    }
 else     if (consumer.isShare()) {
      pool.setShared(pool.getShared() - entQuantity);
    }
    consumer.setEntitlementCount(consumer.getEntitlementCount() - entQuantity);
    consumerCurator.update(consumer);
    poolsToSave.add(pool);
  }
  poolCurator.updateAll(poolsToSave,false,false);
  if (regenCertsAndStatuses) {
    log.debug("String_Node_Str");
    int update=this.entitlementCurator.markDependentEntitlementsDirty(entsToRevoke);
    log.debug("String_Node_Str",update);
  }
  log.info("String_Node_Str");
  poolCurator.batchDelete(poolsToDelete,alreadyDeletedPools);
  log.info("String_Node_Str");
  entitlementCurator.batchDelete(entsToRevoke);
  log.info("String_Node_Str");
  entitlementCurator.flush();
  log.info("String_Node_Str");
  Map<Consumer,List<Entitlement>> consumerSortedEntitlements=entitlementCurator.getDistinctConsumers(entsToRevoke);
  filterAndUpdateStackingEntitlements(consumerSortedEntitlements,alreadyDeletedPools);
  for (  Entitlement ent : entsToRevoke) {
    enforcer.postUnbind(ent.getConsumer(),this,ent);
  }
  if (!regenCertsAndStatuses) {
    log.info("String_Node_Str");
    sendDeletedEvents(entsToRevoke);
    return;
  }
  log.info("String_Node_Str",consumerSortedEntitlements.size());
  int i=1;
  for (  Consumer consumer : consumerSortedEntitlements.keySet()) {
    if (i++ % 1000 == 0) {
      consumerCurator.flush();
    }
    complianceRules.getStatus(consumer);
  }
  consumerCurator.flush();
  log.info("String_Node_Str");
  sendDeletedEvents(entsToRevoke);
}