Program: 63844
Project: 63844
Buggy source:
/** 
 * Removes the 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
 */
@SuppressWarnings({"String_Node_Str","String_Node_Str"}) public Object removeAttribute(Map<String,String> tenantId,String entityName,Object id,String attribute,String listItemId,Object entity,String partner){
  EntityManager em=getEmf().createEntityManager(tenantId);
  String fieldName=null;
  try {
    Class<?> clazz=getClass(entityName);
    ClassDescriptor descriptor=getServerSession().getClassDescriptor(clazz);
    DatabaseMapping mapping=descriptor.getMappingForAttributeName(attribute);
    if (mapping == null) {
      return null;
    }
 else     if (mapping.isObjectReferenceMapping() || mapping.isCollectionMapping()) {
      DatabaseMapping partnerMapping=null;
      Object originalAttributeValue=null;
      ClassDescriptor referenceDescriptor=((ForeignReferenceMapping)mapping).getReferenceDescriptor();
      if (partner != null) {
        partnerMapping=referenceDescriptor.getMappingForAttributeName(partner);
        if (partnerMapping == null) {
          return null;
        }
      }
      Field[] fields=null;
      if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
        fields=AccessController.doPrivileged(new PrivilegedGetDeclaredFields(clazz));
      }
 else {
        fields=PrivilegedAccessHelper.getDeclaredFields(clazz);
      }
      for (int i=0; i < fields.length; i++) {
        Field field=fields[i];
        fieldName=field.getName();
        if (fieldName.equals(attribute)) {
          try {
            Object attributeValue=getAttribute(entity,attribute);
            originalAttributeValue=attributeValue;
            if (attributeValue instanceof Collection) {
              if (listItemId == null) {
                ((Collection)attributeValue).clear();
              }
 else {
                Object realListItemId=IdHelper.buildId(this,referenceDescriptor.getAlias(),listItemId);
                Object member=this.find(referenceDescriptor.getAlias(),realListItemId);
                ((Collection)attributeValue).remove(member);
              }
            }
 else             if (attributeValue instanceof Object) {
              attributeValue=null;
            }
 else {
              attributeValue=0;
            }
            break;
          }
 catch (          Exception e) {
            e.printStackTrace();
            return null;
          }
        }
      }
      transaction.beginTransaction(em);
      entity=em.merge(entity);
      removeMappingValueFromObject(entity,originalAttributeValue,mapping,partnerMapping);
      transaction.commitTransaction(em);
      return entity;
    }
    return null;
  }
 catch (  Exception e) {
    JPARSLogger.fine("String_Node_Str",new Object[]{fieldName,entityName,getName(),e.toString()});
    transaction.rollbackTransaction(em);
    return null;
  }
 finally {
    em.close();
  }
}

Fixed version (ground truth):
/** 
 * Removes the 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
 */
@SuppressWarnings({"String_Node_Str","String_Node_Str"}) public Object removeAttribute(Map<String,String> tenantId,String entityName,Object id,String attribute,String listItemId,Object entity,String partner){
  EntityManager em=getEmf().createEntityManager(tenantId);
  String fieldName=null;
  try {
    Class<?> clazz=getClass(entityName);
    ClassDescriptor descriptor=getServerSession().getClassDescriptor(clazz);
    DatabaseMapping mapping=descriptor.getMappingForAttributeName(attribute);
    if (mapping == null) {
      return null;
    }
 else     if (mapping.isObjectReferenceMapping() || mapping.isCollectionMapping()) {
      DatabaseMapping partnerMapping=null;
      Object originalAttributeValue=null;
      ClassDescriptor referenceDescriptor=((ForeignReferenceMapping)mapping).getReferenceDescriptor();
      if (partner != null) {
        partnerMapping=referenceDescriptor.getMappingForAttributeName(partner);
        if (partnerMapping == null) {
          return null;
        }
      }
      Field[] fields=null;
      if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
        fields=AccessController.doPrivileged(new PrivilegedGetDeclaredFields(clazz));
      }
 else {
        fields=PrivilegedAccessHelper.getDeclaredFields(clazz);
      }
      for (int i=0; i < fields.length; i++) {
        Field field=fields[i];
        fieldName=field.getName();
        if (fieldName.equals(attribute)) {
          try {
            Object attributeValue=getAttribute(entity,attribute);
            originalAttributeValue=attributeValue;
            if (attributeValue instanceof Collection) {
              if (listItemId == null) {
                ((Collection)attributeValue).clear();
              }
 else {
                Object realListItemId=IdHelper.buildId(this,referenceDescriptor.getAlias(),listItemId);
                Object member=this.find(referenceDescriptor.getAlias(),realListItemId);
                ((Collection)attributeValue).remove(member);
              }
            }
 else             if (attributeValue instanceof Object) {
              attributeValue=null;
            }
 else {
              attributeValue=0;
            }
            break;
          }
 catch (          Exception e) {
            e.printStackTrace();
            return null;
          }
        }
      }
      transaction.beginTransaction(em);
      entity=em.merge(entity);
      removeMappingValueFromObject(entity,originalAttributeValue,mapping,partnerMapping);
      transaction.commitTransaction(em);
      return entity;
    }
    return null;
  }
 catch (  Exception e) {
    JPARSLogger.fine("String_Node_Str",new Object[]{DataStorage.get(DataStorage.REQUEST_UNIQUE_ID),fieldName,entityName,getName(),e.toString()});
    transaction.rollbackTransaction(em);
    return null;
  }
 finally {
    em.close();
  }
}