Program: 49490
Project: 49490
Buggy source:
/** 
 * @param pool
 * @param consumer
 * @param stackId
 * @param stackedEntitlements
 */
public PoolUpdate updatePoolFromStackedEntitlements(Pool pool,Consumer consumer,String stackId,List<Entitlement> stackedEnts){
  PoolUpdate update=new PoolUpdate(pool);
  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();
  boolean useDerived=eldestEntPool.getDerivedProductId() != null;
  String prodId=useDerived ? eldestEntPool.getDerivedProductId() : eldestEntPool.getProductId();
  String prodName=useDerived ? eldestEntPool.getDerivedProductName() : eldestEntPool.getProductName();
  update.setProductsChanged(checkForChangedProducts(prodId,prodName,expectedProvidedProds,pool));
  if (!pool.getProductAttributes().equals(expectedAttrs)) {
    pool.getProductAttributes().clear();
    for (    ProductPoolAttribute attr : expectedAttrs) {
      attr.setProductId(pool.getProductId());
      pool.addProductAttribute(attr);
    }
    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):
/** 
 * @param pool
 * @param consumer
 * @param stackId
 * @param stackedEntitlements
 */
public PoolUpdate updatePoolFromStackedEntitlements(Pool pool,Consumer consumer,String stackId,List<Entitlement> stackedEnts){
  PoolUpdate update=new PoolUpdate(pool);
  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>();
  Map<String,ProductPoolAttribute> expectedAttrs=new HashMap<String,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.put(attr.getName(),new ProductPoolAttribute(attr.getName(),attr.getValue(),pool.getProductId()));
      }
    }
 else {
      for (      DerivedProductPoolAttribute attr : nextStackedPool.getDerivedProductAttributes()) {
        expectedAttrs.put(attr.getName(),new ProductPoolAttribute(attr.getName(),attr.getValue(),pool.getProductId()));
      }
    }
  }
  update.setDatesChanged(checkForDateChange(startDate,endDate,pool));
  Pool eldestEntPool=eldest.getPool();
  boolean useDerived=eldestEntPool.getDerivedProductId() != null;
  String prodId=useDerived ? eldestEntPool.getDerivedProductId() : eldestEntPool.getProductId();
  String prodName=useDerived ? eldestEntPool.getDerivedProductName() : eldestEntPool.getProductName();
  update.setProductsChanged(checkForChangedProducts(prodId,prodName,expectedProvidedProds,pool));
  if (!pool.getProductAttributes().equals(expectedAttrs.values())) {
    pool.getProductAttributes().clear();
    for (    ProductPoolAttribute attr : expectedAttrs.values()) {
      attr.setProductId(pool.getProductId());
      pool.addProductAttribute(attr);
    }
    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;
}