Program: 49202
Project: 49202
Buggy source:
private void postBindShareCreate(PoolManager poolManager,Consumer c,Map<String,Entitlement> entitlementMap){
  log.debug("String_Node_Str");
  Owner sharingOwner=c.getOwner();
  Owner recipient=ownerCurator.lookupByKey(c.getRecipientOwnerKey());
  List<Pool> sharedPoolsToCreate=new ArrayList<Pool>();
  for (  Entitlement entitlement : entitlementMap.values()) {
    Pool sourcePool=entitlement.getPool();
    Set<Product> allProducts=new HashSet<Product>();
    allProducts.add(sourcePool.getProduct());
    if (sourcePool.getProvidedProducts() != null) {
      allProducts.addAll(sourcePool.getProvidedProducts());
    }
    if (sourcePool.getDerivedProduct() != null) {
      allProducts.add(sourcePool.getDerivedProduct());
    }
    if (sourcePool.getDerivedProvidedProducts() != null) {
      allProducts.addAll(sourcePool.getDerivedProvidedProducts());
    }
    Map<String,Product> resolvedProducts=resolveProductShares(sharingOwner,recipient,allProducts);
    Product product=resolvedProducts.get(sourcePool.getProduct().getId());
    Set<Product> providedProducts=copySetFromResolved(sourcePool.getProvidedProducts(),resolvedProducts);
    Long q=Long.valueOf(entitlement.getQuantity());
    Date endDate=(entitlement.getEndDateOverride() == null) ? sourcePool.getEndDate() : entitlement.getEndDateOverride();
    Pool sharedPool=new Pool(recipient,product,providedProducts,q,sourcePool.getStartDate(),endDate,sourcePool.getContractNumber(),sourcePool.getAccountNumber(),sourcePool.getOrderNumber());
    if (sourcePool.getDerivedProduct() != null) {
      Product derivedProduct=resolvedProducts.get(sourcePool.getDerivedProduct().getId());
      sharedPool.setDerivedProduct(derivedProduct);
    }
    Set<Product> derivedProvidedProducts=copySetFromResolved(sourcePool.getDerivedProvidedProducts(),resolvedProducts);
    sharedPool.setDerivedProvidedProducts(derivedProvidedProducts);
    if (entitlement != null && entitlement.getPool() != null) {
      sharedPool.setSourceEntitlement(entitlement);
    }
    sharedPool.setSourceSubscription(new SourceSubscription(sourcePool.getSubscriptionId(),entitlement.getId()));
    for (    Entry<String,String> entry : sourcePool.getAttributes().entrySet()) {
      sharedPool.setAttribute(entry.getKey(),entry.getValue());
    }
    sharedPool.setAttribute(Pool.Attributes.DERIVED_POOL,"String_Node_Str");
    sharedPool.setCreatedByShare(Boolean.TRUE);
    sharedPool.setHasSharedAncestor(Boolean.TRUE);
    for (    Branding b : sourcePool.getBranding()) {
      sharedPool.getBranding().add(new Branding(b.getProductId(),b.getType(),b.getName()));
    }
    sharedPoolsToCreate.add(sharedPool);
  }
  if (CollectionUtils.isNotEmpty(sharedPoolsToCreate)) {
    poolManager.createPools(sharedPoolsToCreate);
  }
}

Fixed version (ground truth):
private void postBindShareCreate(PoolManager poolManager,Consumer c,Map<String,Entitlement> entitlementMap){
  log.debug("String_Node_Str");
  Owner sharingOwner=c.getOwner();
  Owner recipient=ownerCurator.lookupByKey(c.getRecipientOwnerKey());
  List<Pool> sharedPoolsToCreate=new ArrayList<Pool>();
  for (  Entitlement entitlement : entitlementMap.values()) {
    Pool sourcePool=entitlement.getPool();
    Set<Product> allProducts=new HashSet<Product>();
    allProducts.add(sourcePool.getProduct());
    if (sourcePool.getProvidedProducts() != null) {
      allProducts.addAll(sourcePool.getProvidedProducts());
    }
    if (sourcePool.getDerivedProduct() != null) {
      allProducts.add(sourcePool.getDerivedProduct());
    }
    if (sourcePool.getDerivedProvidedProducts() != null) {
      allProducts.addAll(sourcePool.getDerivedProvidedProducts());
    }
    Map<String,Product> resolvedProducts=resolveProductShares(sharingOwner,recipient,allProducts);
    Product product=resolvedProducts.get(sourcePool.getProduct().getId());
    Set<Product> providedProducts=copySetFromResolved(sourcePool.getProvidedProducts(),resolvedProducts);
    Long q=Long.valueOf(entitlement.getQuantity());
    Date endDate=(entitlement.getEndDateOverride() == null) ? sourcePool.getEndDate() : entitlement.getEndDateOverride();
    Pool sharedPool=new Pool(recipient,product,providedProducts,q,sourcePool.getStartDate(),endDate,sourcePool.getContractNumber(),sourcePool.getAccountNumber(),sourcePool.getOrderNumber());
    if (sourcePool.getDerivedProduct() != null) {
      Product derivedProduct=resolvedProducts.get(sourcePool.getDerivedProduct().getId());
      sharedPool.setDerivedProduct(derivedProduct);
    }
    Set<Product> derivedProvidedProducts=copySetFromResolved(sourcePool.getDerivedProvidedProducts(),resolvedProducts);
    sharedPool.setDerivedProvidedProducts(derivedProvidedProducts);
    if (entitlement != null && entitlement.getPool() != null) {
      sharedPool.setSourceEntitlement(entitlement);
    }
    String subscriptionId=sourcePool.getSubscriptionId();
    if (subscriptionId != null && !subscriptionId.isEmpty()) {
      sharedPool.setSourceSubscription(new SourceSubscription(subscriptionId,entitlement.getId()));
    }
    for (    Entry<String,String> entry : sourcePool.getAttributes().entrySet()) {
      sharedPool.setAttribute(entry.getKey(),entry.getValue());
    }
    sharedPool.setAttribute(Pool.Attributes.DERIVED_POOL,"String_Node_Str");
    sharedPool.setCreatedByShare(Boolean.TRUE);
    sharedPool.setHasSharedAncestor(Boolean.TRUE);
    for (    Branding b : sourcePool.getBranding()) {
      sharedPool.getBranding().add(new Branding(b.getProductId(),b.getType(),b.getName()));
    }
    sharedPoolsToCreate.add(sharedPool);
  }
  if (CollectionUtils.isNotEmpty(sharedPoolsToCreate)) {
    poolManager.createPools(sharedPoolsToCreate);
  }
}