Program: 49494
Project: 49494
Buggy source:
/** 
 * Updates the pool based on the entitlements in the specified stack.
 * @param pool
 * @param consumer
 * @param stackId
 * @return pool update specifics
 */
public PoolUpdate updatePoolFromStack(Pool pool,Consumer consumer,String stackId){
  PoolUpdate update=new PoolUpdate(pool);
  List<Entitlement> stackedEnts=this.entCurator.findByStackId(consumer,stackId);
  if (stackedEnts.isEmpty()) {
    return update;
  }
  pool.setSourceStackId(stackId);
  pool.setSourceEntitlement(null);
  pool.setSourceConsumer(consumer);
  pool.setSubscriptionId(null);
  Entitlement eldest=null;
  Date startDate=null;
  Date endDate=null;
  Set<ProvidedProduct> expectedProvidedProds=new HashSet<ProvidedProduct>();
  Set<ProductPoolAttribute> expectedAttrs=new HashSet<ProductPoolAttribute>();
  for (  Entitlement nextStacked : stackedEnts) {
    if (eldest == null || nextStacked.getCreated().before(eldest.getCreated())) {
      eldest=nextStacked;
    }
    if (startDate == null || nextStacked.getStartDate().before(startDate)) {
      startDate=nextStacked.getStartDate();
    }
    if (endDate == null || nextStacked.getEndDate().after(endDate)) {
      endDate=nextStacked.getEndDate();
    }
    Pool nextStackedPool=nextStacked.getPool();
    if (nextStackedPool.getDerivedProductId() == null) {
      for (      ProvidedProduct pp : nextStackedPool.getProvidedProducts()) {
        expectedProvidedProds.add(new ProvidedProduct(pp.getProductId(),pp.getProductName(),pool));
      }
    }
 else {
      for (      DerivedProvidedProduct pp : nextStackedPool.getDerivedProvidedProducts()) {
        expectedProvidedProds.add(new ProvidedProduct(pp.getProductId(),pp.getProductName(),pool));
      }
    }
    if (nextStackedPool.getDerivedProductId() == null) {
      for (      ProductPoolAttribute attr : nextStackedPool.getProductAttributes()) {
        expectedAttrs.add(new ProductPoolAttribute(attr.getName(),attr.getValue(),pool.getProductId()));
      }
    }
 else {
      for (      DerivedProductPoolAttribute attr : nextStackedPool.getDerivedProductAttributes()) {
        expectedAttrs.add(new ProductPoolAttribute(attr.getName(),attr.getValue(),pool.getProductId()));
      }
    }
  }
  update.setDatesChanged(checkForDateChange(startDate,endDate,pool));
  Pool eldestEntPool=eldest.getPool();
  update.setProductsChanged(checkForChangedProducts(eldestEntPool.getProductId(),eldestEntPool.getProductName(),expectedProvidedProds,pool));
  if (!pool.getProductAttributes().equals(expectedAttrs)) {
    for (    ProductPoolAttribute attr : expectedAttrs) {
      attr.setProductId(pool.getProductId());
    }
    pool.getProductAttributes().clear();
    pool.getProductAttributes().addAll(expectedAttrs);
    update.setProductAttributesChanged(true);
  }
  if (!StringUtils.equals(eldestEntPool.getContractNumber(),pool.getContractNumber()) || !StringUtils.equals(eldestEntPool.getOrderNumber(),pool.getOrderNumber()) || !StringUtils.equals(eldestEntPool.getAccountNumber(),pool.getAccountNumber())) {
    pool.setContractNumber(eldestEntPool.getContractNumber());
    pool.setAccountNumber(eldestEntPool.getAccountNumber());
    pool.setOrderNumber(eldestEntPool.getOrderNumber());
    update.setOrderChanged(true);
  }
  return update;
}

Fixed version (ground truth):
/** 
 * Updates the pool based on the entitlements in the specified stack.
 * @param pool
 * @param consumer
 * @param stackId
 * @return pool update specifics
 */
public PoolUpdate updatePoolFromStack(Pool pool,Consumer consumer,String stackId){
  List<Entitlement> stackedEnts=this.entCurator.findByStackId(consumer,stackId);
  return this.updatePoolFromStackedEntitlements(pool,consumer,stackId,stackedEnts);
}