Program: 49252
Project: 49252
Buggy source:
/** 
 * Creates or updates content from the given content DTOs, omitting product updates for the provided Red Hat product IDs. <p></p> The content DTOs provided in the given map should be mapped by the content'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 content
 * @param contentData A mapping of Red Hat content ID to content DTOs to import
 * @param importedProductIds A set of Red Hat product IDs specifying products which are being imported and should not be updated as part of this import operation
 * @return A mapping of Red Hat content ID to content entities representing the imported content
 */
@SuppressWarnings("String_Node_Str") public Map<String,Content> importContent(Owner owner,Map<String,ContentData> contentData,Set<String> importedProductIds){
  if (owner == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (contentData == null || contentData.isEmpty()) {
    return new HashMap<String,Content>();
  }
  Map<String,Content> importedContent=new HashMap<String,Content>();
  Map<String,Content> createdContent=new HashMap<String,Content>();
  Map<String,Content> updatedContent=new HashMap<String,Content>();
  Map<String,Integer> contentVersions=new HashMap<String,Integer>();
  Map<String,Content> sourceContent=new HashMap<String,Content>();
  Map<String,List<Content>> existingVersions=new HashMap<String,List<Content>>();
  List<OwnerContent> ownerContentBuffer=new LinkedList<OwnerContent>();
  for (  Content content : this.ownerContentCurator.getContentByIds(owner,contentData.keySet())) {
    ContentData update=contentData.get(content.getId());
    if (!content.isChangedBy(update)) {
      importedContent.put(content.getId(),content);
      continue;
    }
    sourceContent.put(content.getId(),content);
    content=this.applyContentChanges((Content)content.clone(),update);
    updatedContent.put(content.getId(),content);
    contentVersions.put(content.getId(),content.getEntityVersion());
  }
  for (  ContentData update : contentData.values()) {
    if (!updatedContent.containsKey(update.getId()) && !importedContent.containsKey(update.getId())) {
      if (update.getId() == null || update.getType() == null || update.getLabel() == null || update.getName() == null || update.getVendor() == null) {
        throw new IllegalStateException("String_Node_Str" + update);
      }
      Content content=this.applyContentChanges(new Content(update.getId()),update);
      createdContent.put(content.getId(),content);
      contentVersions.put(content.getId(),content.getEntityVersion());
    }
  }
  for (  Content alt : this.contentCurator.getContentByVersions(contentVersions)) {
    List<Content> alternates=existingVersions.get(alt.getId());
    if (alternates == null) {
      alternates=new LinkedList<Content>();
      existingVersions.put(alt.getId(),alternates);
    }
    alternates.add(alt);
  }
  contentVersions.clear();
  contentVersions=null;
  Iterator<Content> iterator=createdContent.values().iterator();
  createdContentLoop:   while (iterator.hasNext()) {
    Content created=iterator.next();
    List<Content> alternates=existingVersions.get(created.getId());
    if (alternates != null) {
      for (      Content alt : alternates) {
        if (created.equals(alt)) {
          ownerContentBuffer.add(new OwnerContent(owner,alt));
          importedContent.put(alt.getId(),alt);
          iterator.remove();
          continue createdContentLoop;
        }
      }
    }
    ownerContentBuffer.add(new OwnerContent(owner,created));
  }
  updatedContentLoop:   for (  Map.Entry<String,Content> entry : updatedContent.entrySet()) {
    Content updated=entry.getValue();
    List<Content> alternates=existingVersions.get(updated.getId());
    if (alternates != null) {
      for (      Content alt : alternates) {
        if (updated.equals(alt)) {
          updated=alt;
          entry.setValue(alt);
          continue updatedContentLoop;
        }
      }
    }
    updated.setUuid(null);
    createdContent.put(updated.getId(),updated);
  }
  this.contentCurator.saveAll(createdContent.values(),true,false);
  this.ownerContentCurator.saveAll(ownerContentBuffer,true,true);
  List<Product> affectedProducts=this.productCurator.getProductsWithContent(owner,sourceContent.keySet(),importedProductIds).list();
  if (affectedProducts != null && !affectedProducts.isEmpty()) {
    Map<String,Content> affectedProductsContent=new HashMap<String,Content>();
    for (    Content content : this.contentCurator.getContentByProducts(affectedProducts)) {
      affectedProductsContent.put(content.getId(),content);
    }
    affectedProductsContent.putAll(updatedContent);
    Map<String,ProductData> affectedProductData=new HashMap<String,ProductData>();
    for (    Product product : affectedProducts) {
      ProductData productData=product.toDTO();
      for (      ProductContentData pcd : productData.getProductContent()) {
        ContentData cdata=pcd.getContent();
        Content content=updatedContent.get(cdata.getId());
        if (content != null) {
          pcd.setContent(content.toDTO());
        }
      }
      affectedProductData.put(productData.getId(),productData);
    }
    this.productManager.importProducts(owner,affectedProductData,affectedProductsContent);
  }
  Map<String,String> contentUuidMap=new HashMap<String,String>();
  for (  Content update : updatedContent.values()) {
    Content source=sourceContent.get(update.getId());
    contentUuidMap.put(source.getUuid(),update.getUuid());
  }
  this.ownerContentCurator.updateOwnerContentReferences(owner,contentUuidMap);
  importedContent.putAll(createdContent);
  importedContent.putAll(updatedContent);
  return importedContent;
}

Fixed version (ground truth):
/** 
 * Creates or updates content from the given content DTOs, omitting product updates for the provided Red Hat product IDs. <p></p> The content DTOs provided in the given map should be mapped by the content'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 content
 * @param contentData A mapping of Red Hat content ID to content DTOs to import
 * @param importedProductIds A set of Red Hat product IDs specifying products which are being imported and should not be updated as part of this import operation
 * @return A mapping of Red Hat content ID to content entities representing the imported content
 */
@SuppressWarnings("String_Node_Str") public ImportResult<Content> importContent(Owner owner,Map<String,ContentData> contentData,Set<String> importedProductIds){
  if (owner == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  ImportResult<Content> importResult=new ImportResult<Content>();
  if (contentData == null || contentData.isEmpty()) {
    return importResult;
  }
  Map<String,Content> skippedContent=importResult.getSkippedEntities();
  Map<String,Content> createdContent=importResult.getCreatedEntities();
  Map<String,Content> updatedContent=importResult.getUpdatedEntities();
  Map<String,Integer> contentVersions=new HashMap<String,Integer>();
  Map<String,Content> sourceContent=new HashMap<String,Content>();
  Map<String,List<Content>> existingVersions=new HashMap<String,List<Content>>();
  List<OwnerContent> ownerContentBuffer=new LinkedList<OwnerContent>();
  for (  Content content : this.ownerContentCurator.getContentByIds(owner,contentData.keySet())) {
    ContentData update=contentData.get(content.getId());
    if (!content.isChangedBy(update)) {
      skippedContent.put(content.getId(),content);
      continue;
    }
    sourceContent.put(content.getId(),content);
    content=this.applyContentChanges((Content)content.clone(),update);
    updatedContent.put(content.getId(),content);
    contentVersions.put(content.getId(),content.getEntityVersion());
  }
  for (  ContentData update : contentData.values()) {
    if (!skippedContent.containsKey(update.getId()) && !updatedContent.containsKey(update.getId())) {
      if (update.getId() == null || update.getType() == null || update.getLabel() == null || update.getName() == null || update.getVendor() == null) {
        throw new IllegalStateException("String_Node_Str" + update);
      }
      Content content=this.applyContentChanges(new Content(update.getId()),update);
      createdContent.put(content.getId(),content);
      contentVersions.put(content.getId(),content.getEntityVersion());
    }
  }
  for (  Content alt : this.contentCurator.getContentByVersions(contentVersions)) {
    List<Content> alternates=existingVersions.get(alt.getId());
    if (alternates == null) {
      alternates=new LinkedList<Content>();
      existingVersions.put(alt.getId(),alternates);
    }
    alternates.add(alt);
  }
  contentVersions.clear();
  contentVersions=null;
  Map<String,Content> stagedEntities=new HashMap<String,Content>(createdContent);
  Iterator<Content> iterator=stagedEntities.values().iterator();
  createdContentLoop:   while (iterator.hasNext()) {
    Content created=iterator.next();
    List<Content> alternates=existingVersions.get(created.getId());
    if (alternates != null) {
      for (      Content alt : alternates) {
        if (created.equals(alt)) {
          ownerContentBuffer.add(new OwnerContent(owner,alt));
          createdContent.put(alt.getId(),alt);
          iterator.remove();
          continue createdContentLoop;
        }
      }
    }
    ownerContentBuffer.add(new OwnerContent(owner,created));
  }
  updatedContentLoop:   for (  Map.Entry<String,Content> entry : updatedContent.entrySet()) {
    Content updated=entry.getValue();
    List<Content> alternates=existingVersions.get(updated.getId());
    if (alternates != null) {
      for (      Content alt : alternates) {
        if (updated.equals(alt)) {
          updated=alt;
          entry.setValue(alt);
          continue updatedContentLoop;
        }
      }
    }
    updated.setUuid(null);
    stagedEntities.put(updated.getId(),updated);
  }
  this.contentCurator.saveAll(stagedEntities.values(),true,false);
  this.ownerContentCurator.saveAll(ownerContentBuffer,true,true);
  List<Product> affectedProducts=this.productCurator.getProductsWithContent(owner,sourceContent.keySet(),importedProductIds).list();
  if (affectedProducts != null && !affectedProducts.isEmpty()) {
    Map<String,Content> affectedProductsContent=new HashMap<String,Content>();
    for (    Content content : this.contentCurator.getContentByProducts(affectedProducts)) {
      affectedProductsContent.put(content.getId(),content);
    }
    affectedProductsContent.putAll(updatedContent);
    Map<String,ProductData> affectedProductData=new HashMap<String,ProductData>();
    for (    Product product : affectedProducts) {
      ProductData productData=product.toDTO();
      for (      ProductContentData pcd : productData.getProductContent()) {
        ContentData cdata=pcd.getContent();
        Content content=updatedContent.get(cdata.getId());
        if (content != null) {
          pcd.setContent(content.toDTO());
        }
      }
      affectedProductData.put(productData.getId(),productData);
    }
    this.productManager.importProducts(owner,affectedProductData,affectedProductsContent);
  }
  Map<String,String> contentUuidMap=new HashMap<String,String>();
  for (  Content update : updatedContent.values()) {
    Content source=sourceContent.get(update.getId());
    contentUuidMap.put(source.getUuid(),update.getUuid());
  }
  this.ownerContentCurator.updateOwnerContentReferences(owner,contentUuidMap);
  return importResult;
}