Program: 49254
Project: 49254
Buggy source:
/** 
 * Creates or updates products from the given products DTOs, using the provided content for content lookup and resolution. <p></p> The product DTOs provided in the given map should be mapped by the product's Red Hat ID. If the mappings are incorrect or inconsistent, the result of this method is undefined.
 * @param owner The owner for which to import the given product
 * @param productData A mapping of Red Hat product ID to product DTOs to import
 * @param importedContent A mapping of Red Hat content ID to content instances to use to lookup and resolve content references on the provided product DTOs.
 * @return A mapping of Red Hat content ID to content entities representing the imported content
 */
public Map<String,Product> importProducts(Owner owner,Map<String,ProductData> productData,Map<String,Content> importedContent){
  if (owner == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (productData == null || productData.isEmpty()) {
    return new HashMap<String,Product>();
  }
  Map<String,Product> importedProducts=new HashMap<String,Product>();
  Map<String,Product> createdProducts=new HashMap<String,Product>();
  Map<String,Product> updatedProducts=new HashMap<String,Product>();
  Map<String,Integer> productVersions=new HashMap<String,Integer>();
  Map<String,Product> sourceProducts=new HashMap<String,Product>();
  Map<String,List<Product>> existingVersions=new HashMap<String,List<Product>>();
  List<OwnerProduct> ownerProductBuffer=new LinkedList<OwnerProduct>();
  for (  Product product : this.ownerProductCurator.getProductsByIds(owner,productData.keySet())) {
    ProductData update=productData.get(product.getId());
    if (!product.isChangedBy(update)) {
      importedProducts.put(product.getId(),product);
      continue;
    }
    sourceProducts.put(product.getId(),product);
    product=this.applyProductChanges((Product)product.clone(),update,importedContent);
    updatedProducts.put(product.getId(),product);
    productVersions.put(product.getId(),product.getEntityVersion());
  }
  for (  ProductData update : productData.values()) {
    if (!updatedProducts.containsKey(update.getId()) && !importedProducts.containsKey(update.getId())) {
      if (update.getId() == null || update.getName() == null) {
        throw new IllegalStateException("String_Node_Str" + update);
      }
      Product product=new Product(update.getId(),update.getName());
      product=this.applyProductChanges(product,update,importedContent);
      createdProducts.put(product.getId(),product);
      productVersions.put(product.getId(),product.getEntityVersion());
    }
  }
  for (  Product alt : this.productCurator.getProductByVersions(productVersions)) {
    List<Product> alternates=existingVersions.get(alt.getId());
    if (alternates == null) {
      alternates=new LinkedList<Product>();
      existingVersions.put(alt.getId(),alternates);
    }
    alternates.add(alt);
  }
  productVersions.clear();
  productVersions=null;
  Iterator<Product> iterator=createdProducts.values().iterator();
  createdProductLoop:   while (iterator.hasNext()) {
    Product created=iterator.next();
    List<Product> alternates=existingVersions.get(created.getId());
    if (alternates != null) {
      for (      Product alt : alternates) {
        if (created.equals(alt)) {
          ownerProductBuffer.add(new OwnerProduct(owner,alt));
          importedProducts.put(alt.getId(),alt);
          iterator.remove();
          continue createdProductLoop;
        }
      }
    }
    ownerProductBuffer.add(new OwnerProduct(owner,created));
  }
  updatedProductLoop:   for (  Map.Entry<String,Product> entry : updatedProducts.entrySet()) {
    Product updated=entry.getValue();
    List<Product> alternates=existingVersions.get(updated.getId());
    if (alternates != null) {
      for (      Product alt : alternates) {
        if (updated.equals(alt)) {
          updated=alt;
          entry.setValue(alt);
          continue updatedProductLoop;
        }
      }
    }
    updated.setUuid(null);
    createdProducts.put(updated.getId(),updated);
  }
  this.productCurator.saveAll(createdProducts.values(),true,false);
  this.ownerProductCurator.saveAll(ownerProductBuffer,true,true);
  Map<String,String> productUuidMap=new HashMap<String,String>();
  for (  Product update : updatedProducts.values()) {
    Product source=sourceProducts.get(update.getId());
    productUuidMap.put(source.getUuid(),update.getUuid());
  }
  this.ownerProductCurator.updateOwnerProductReferences(owner,productUuidMap);
  importedProducts.putAll(createdProducts);
  importedProducts.putAll(updatedProducts);
  return importedProducts;
}

Fixed version (ground truth):
/** 
 * Creates or updates products from the given products DTOs, using the provided content for content lookup and resolution. <p></p> The product DTOs provided in the given map should be mapped by the product's Red Hat ID. If the mappings are incorrect or inconsistent, the result of this method is undefined.
 * @param owner The owner for which to import the given product
 * @param productData A mapping of Red Hat product ID to product DTOs to import
 * @param importedContent A mapping of Red Hat content ID to content instances to use to lookup and resolve content references on the provided product DTOs.
 * @return A mapping of Red Hat content ID to content entities representing the imported content
 */
public ImportResult<Product> importProducts(Owner owner,Map<String,ProductData> productData,Map<String,Content> importedContent){
  if (owner == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  ImportResult<Product> importResult=new ImportResult<Product>();
  if (productData == null || productData.isEmpty()) {
    return importResult;
  }
  Map<String,Product> skippedProducts=importResult.getSkippedEntities();
  Map<String,Product> createdProducts=importResult.getCreatedEntities();
  Map<String,Product> updatedProducts=importResult.getUpdatedEntities();
  Map<String,Integer> productVersions=new HashMap<String,Integer>();
  Map<String,Product> sourceProducts=new HashMap<String,Product>();
  Map<String,List<Product>> existingVersions=new HashMap<String,List<Product>>();
  List<OwnerProduct> ownerProductBuffer=new LinkedList<OwnerProduct>();
  for (  Product product : this.ownerProductCurator.getProductsByIds(owner,productData.keySet())) {
    ProductData update=productData.get(product.getId());
    if (!product.isChangedBy(update)) {
      skippedProducts.put(product.getId(),product);
      continue;
    }
    sourceProducts.put(product.getId(),product);
    product=this.applyProductChanges((Product)product.clone(),update,importedContent);
    updatedProducts.put(product.getId(),product);
    productVersions.put(product.getId(),product.getEntityVersion());
  }
  for (  ProductData update : productData.values()) {
    if (!skippedProducts.containsKey(update.getId()) && !updatedProducts.containsKey(update.getId())) {
      if (update.getId() == null || update.getName() == null) {
        throw new IllegalStateException("String_Node_Str" + update);
      }
      Product product=new Product(update.getId(),update.getName());
      product=this.applyProductChanges(product,update,importedContent);
      createdProducts.put(product.getId(),product);
      productVersions.put(product.getId(),product.getEntityVersion());
    }
  }
  for (  Product alt : this.productCurator.getProductByVersions(productVersions)) {
    List<Product> alternates=existingVersions.get(alt.getId());
    if (alternates == null) {
      alternates=new LinkedList<Product>();
      existingVersions.put(alt.getId(),alternates);
    }
    alternates.add(alt);
  }
  productVersions.clear();
  productVersions=null;
  Map<String,Product> stagedEntities=new HashMap<String,Product>(createdProducts);
  Iterator<Product> iterator=stagedEntities.values().iterator();
  createdProductLoop:   while (iterator.hasNext()) {
    Product created=iterator.next();
    List<Product> alternates=existingVersions.get(created.getId());
    if (alternates != null) {
      for (      Product alt : alternates) {
        if (created.equals(alt)) {
          ownerProductBuffer.add(new OwnerProduct(owner,alt));
          createdProducts.put(alt.getId(),alt);
          iterator.remove();
          continue createdProductLoop;
        }
      }
    }
    ownerProductBuffer.add(new OwnerProduct(owner,created));
  }
  updatedProductLoop:   for (  Map.Entry<String,Product> entry : updatedProducts.entrySet()) {
    Product updated=entry.getValue();
    List<Product> alternates=existingVersions.get(updated.getId());
    if (alternates != null) {
      for (      Product alt : alternates) {
        if (updated.equals(alt)) {
          updated=alt;
          entry.setValue(alt);
          continue updatedProductLoop;
        }
      }
    }
    updated.setUuid(null);
    stagedEntities.put(updated.getId(),updated);
  }
  this.productCurator.saveAll(stagedEntities.values(),true,false);
  this.ownerProductCurator.saveAll(ownerProductBuffer,true,true);
  Map<String,String> productUuidMap=new HashMap<String,String>();
  for (  Product update : updatedProducts.values()) {
    Product source=sourceProducts.get(update.getId());
    productUuidMap.put(source.getUuid(),update.getUuid());
  }
  this.ownerProductCurator.updateOwnerProductReferences(owner,productUuidMap);
  return importResult;
}