Program: 172191
Project: 172191
Buggy source:
/** 
 * @param uuid                          the node UUID, or <tt>null</tt> to auto-generate
 * @param aclId                         an ACL ID if available
 * @param auditableProps                <tt>null</tt> to auto-generate or provide a value to explicitly set
 * @param deleted                       <tt>true</tt> to create an already-deleted node (used for leaving trails of moved nodes)
 */
private NodeEntity newNodeImpl(StoreEntity store,String uuid,QName nodeTypeQName,Long aclId,boolean deleted,AuditablePropertiesEntity auditableProps) throws InvalidTypeException {
  NodeEntity node=new NodeEntity();
  node.setStore(store);
  if (uuid == null) {
    node.setUuid(GUID.generate());
  }
 else {
    node.setUuid(uuid);
  }
  Long typeQNameId=qnameDAO.getOrCreateQName(nodeTypeQName).getFirst();
  node.setTypeQNameId(typeQNameId);
  node.setAclId(aclId);
  node.setDeleted(deleted);
  TransactionEntity txn=getCurrentTransaction();
  node.setTransaction(txn);
  Set<QName> nodeAspects=null;
  if (auditableProps != null) {
    node.setAuditableProperties(auditableProps);
    nodeAspects=Collections.singleton(ContentModel.ASPECT_AUDITABLE);
  }
 else   if (AuditablePropertiesEntity.hasAuditableAspect(nodeTypeQName,dictionaryService)) {
    auditableProps=new AuditablePropertiesEntity();
    auditableProps.setAuditValues(null,null,true,0L);
    node.setAuditableProperties(auditableProps);
    nodeAspects=Collections.singleton(ContentModel.ASPECT_AUDITABLE);
  }
 else {
    nodeAspects=Collections.<QName>emptySet();
  }
  Long id=null;
  try {
    id=insertNode(node);
  }
 catch (  Throwable e) {
    NodeRef targetNodeRef=node.getNodeRef();
    NodeEntity deletedNode=selectNodeByNodeRef(targetNodeRef,true);
    if (deletedNode != null) {
      Long deletedNodeId=deletedNode.getId();
      deleteNodeById(deletedNodeId,true);
      id=insertNode(node);
    }
 else {
      throw new AlfrescoRuntimeException("String_Node_Str" + node,e);
    }
  }
  node.setId(id);
  node.lock();
  nodesCache.setValue(id,node);
  setNodeAspectsCached(id,nodeAspects);
  setNodePropertiesCached(id,Collections.<QName,Serializable>emptyMap());
  if (isDebugEnabled) {
    logger.debug("String_Node_Str" + "String_Node_Str" + node);
  }
  return node;
}

Fixed version (ground truth):
/** 
 * @param uuid                          the node UUID, or <tt>null</tt> to auto-generate
 * @param aclId                         an ACL ID if available
 * @param auditableProps                <tt>null</tt> to auto-generate or provide a value to explicitly set
 * @param deleted                       <tt>true</tt> to create an already-deleted node (used for leaving trails of moved nodes)
 */
private NodeEntity newNodeImpl(StoreEntity store,String uuid,QName nodeTypeQName,Long aclId,boolean deleted,AuditablePropertiesEntity auditableProps) throws InvalidTypeException {
  NodeEntity node=new NodeEntity();
  node.setStore(store);
  if (uuid == null) {
    node.setUuid(GUID.generate());
  }
 else {
    node.setUuid(uuid);
  }
  Long typeQNameId=qnameDAO.getOrCreateQName(nodeTypeQName).getFirst();
  node.setTypeQNameId(typeQNameId);
  node.setAclId(aclId);
  node.setDeleted(deleted);
  TransactionEntity txn=getCurrentTransaction();
  node.setTransaction(txn);
  boolean addAuditableAspect=false;
  if (auditableProps != null) {
    node.setAuditableProperties(auditableProps);
    addAuditableAspect=true;
  }
 else   if (AuditablePropertiesEntity.hasAuditableAspect(nodeTypeQName,dictionaryService)) {
    auditableProps=new AuditablePropertiesEntity();
    auditableProps.setAuditValues(null,null,true,0L);
    node.setAuditableProperties(auditableProps);
    addAuditableAspect=true;
  }
  Long id=null;
  try {
    id=insertNode(node);
  }
 catch (  Throwable e) {
    NodeRef targetNodeRef=node.getNodeRef();
    NodeEntity deletedNode=selectNodeByNodeRef(targetNodeRef,true);
    if (deletedNode != null) {
      Long deletedNodeId=deletedNode.getId();
      deleteNodeById(deletedNodeId,true);
      id=insertNode(node);
    }
 else {
      throw new AlfrescoRuntimeException("String_Node_Str" + node,e);
    }
  }
  node.setId(id);
  Set<QName> nodeAspects=null;
  if (addAuditableAspect) {
    Long auditableAspectQNameId=qnameDAO.getOrCreateQName(ContentModel.ASPECT_AUDITABLE).getFirst();
    insertNodeAspect(id,auditableAspectQNameId);
    nodeAspects=Collections.<QName>singleton(ContentModel.ASPECT_AUDITABLE);
  }
 else {
    nodeAspects=Collections.<QName>emptySet();
  }
  node.lock();
  nodesCache.setValue(id,node);
  setNodeAspectsCached(id,nodeAspects);
  setNodePropertiesCached(id,Collections.<QName,Serializable>emptyMap());
  if (isDebugEnabled) {
    logger.debug("String_Node_Str" + "String_Node_Str" + node);
  }
  return node;
}