Program: 63838
Project: 63838
Buggy source:
/** 
 * Update or add attribute.
 * @param tenantId the tenant id
 * @param entityName the entity name
 * @param id the id
 * @param properties the properties
 * @param attribute the attribute
 * @param attributeValue the attribute value
 * @param partner the partner
 * @return the object
 */
public Object updateOrAddAttribute(Map<String,String> tenantId,String entityName,Object id,Map<String,Object> properties,String attribute,Object attributeValue,String partner){
  EntityManager em=getEmf().createEntityManager(tenantId);
  try {
    ClassDescriptor descriptor=getServerSession().getClassDescriptor(getClass(entityName));
    DatabaseMapping mapping=descriptor.getMappingForAttributeName(attribute);
    Object object=null;
    if (mapping == null) {
      return null;
    }
 else     if (mapping.isObjectReferenceMapping() || mapping.isCollectionMapping()) {
      DatabaseMapping partnerMapping=null;
      if (partner != null) {
        ClassDescriptor referenceDescriptor=((ForeignReferenceMapping)mapping).getReferenceDescriptor();
        partnerMapping=referenceDescriptor.getMappingForAttributeName(partner);
        if (partnerMapping == null) {
          return null;
        }
      }
      transaction.beginTransaction(em);
      try {
        object=em.find(getClass(entityName),id,properties);
        if (object == null) {
          return null;
        }
        attributeValue=em.merge(attributeValue);
        setMappingValueInObject(object,attributeValue,mapping,partnerMapping);
        transaction.commitTransaction(em);
      }
 catch (      Exception e) {
        JPARSLogger.fine("String_Node_Str",new Object[]{entityName,getName(),e.toString()});
        transaction.rollbackTransaction(em);
        return null;
      }
    }
 else {
      return null;
    }
    return object;
  }
  finally {
    em.close();
  }
}

Fixed version (ground truth):
/** 
 * Update or add attribute.
 * @param tenantId the tenant id
 * @param entityName the entity name
 * @param id the id
 * @param properties the properties
 * @param attribute the attribute
 * @param attributeValue the attribute value
 * @param partner the partner
 * @return the object
 */
public Object updateOrAddAttribute(Map<String,String> tenantId,String entityName,Object id,Map<String,Object> properties,String attribute,Object attributeValue,String partner){
  EntityManager em=getEmf().createEntityManager(tenantId);
  try {
    ClassDescriptor descriptor=getServerSession().getClassDescriptor(getClass(entityName));
    DatabaseMapping mapping=descriptor.getMappingForAttributeName(attribute);
    Object object=null;
    if (mapping == null) {
      return null;
    }
 else     if (mapping.isObjectReferenceMapping() || mapping.isCollectionMapping()) {
      DatabaseMapping partnerMapping=null;
      if (partner != null) {
        ClassDescriptor referenceDescriptor=((ForeignReferenceMapping)mapping).getReferenceDescriptor();
        partnerMapping=referenceDescriptor.getMappingForAttributeName(partner);
        if (partnerMapping == null) {
          return null;
        }
      }
      transaction.beginTransaction(em);
      try {
        object=em.find(getClass(entityName),id,properties);
        if (object == null) {
          return null;
        }
        attributeValue=em.merge(attributeValue);
        setMappingValueInObject(object,attributeValue,mapping,partnerMapping);
        transaction.commitTransaction(em);
      }
 catch (      RollbackException e) {
        JPARSLogger.fine("String_Node_Str",new Object[]{DataStorage.get(DataStorage.REQUEST_UNIQUE_ID),entityName,getName(),e.toString()});
        return null;
      }
catch (      Exception e) {
        JPARSLogger.fine("String_Node_Str",new Object[]{DataStorage.get(DataStorage.REQUEST_UNIQUE_ID),entityName,getName(),e.toString()});
        transaction.rollbackTransaction(em);
        return null;
      }
    }
 else {
      return null;
    }
    return object;
  }
  finally {
    em.close();
  }
}