Program: 63289
Project: 63289
Buggy source:
/** 
 * Extract primary key attribute values from the domainObject.
 */
public Object extractPrimaryKeyFromObject(Object domainObject,AbstractSession session,boolean shouldReturnNullIfNull){
  if (domainObject == null) {
    return null;
  }
  boolean isPersistenceEntity=(domainObject instanceof PersistenceEntity) && (!isXMLObjectBuilder());
  if (isPersistenceEntity) {
    Object primaryKey=((PersistenceEntity)domainObject)._persistence_getId();
    if (primaryKey != null) {
      return primaryKey;
    }
  }
  ClassDescriptor descriptor=this.descriptor;
  boolean isNull=false;
  if (descriptor.hasInheritance() && (domainObject.getClass() != descriptor.getJavaClass()) && (!domainObject.getClass().getSuperclass().equals(descriptor.getJavaClass()))) {
    return session.getDescriptor(domainObject).getObjectBuilder().extractPrimaryKeyFromObject(domainObject,session,shouldReturnNullIfNull);
  }
  CacheKeyType cacheKeyType=descriptor.getCachePolicy().getCacheKeyType();
  List<DatabaseField> primaryKeyFields=descriptor.getPrimaryKeyFields();
  Object[] primaryKeyValues=null;
  if (cacheKeyType != CacheKeyType.ID_VALUE) {
    primaryKeyValues=new Object[primaryKeyFields.size()];
  }
  List<DatabaseMapping> mappings=getPrimaryKeyMappings();
  int size=mappings.size();
  if (descriptor.hasSimplePrimaryKey()) {
    for (int index=0; index < size; index++) {
      AbstractColumnMapping mapping=(AbstractColumnMapping)mappings.get(index);
      Object keyValue=mapping.valueFromObject(domainObject,primaryKeyFields.get(index),session);
      if (isPrimaryKeyComponentInvalid(keyValue,index)) {
        if (shouldReturnNullIfNull) {
          return null;
        }
        isNull=true;
      }
      if (cacheKeyType == CacheKeyType.ID_VALUE) {
        if (isPersistenceEntity && (!isNull)) {
          ((PersistenceEntity)domainObject)._persistence_setId(keyValue);
        }
        return keyValue;
      }
 else {
        primaryKeyValues[index]=keyValue;
      }
    }
  }
 else {
    AbstractRecord databaseRow=createRecordForPKExtraction(size,session);
    for (int index=0; index < size; index++) {
      DatabaseMapping mapping=mappings.get(index);
      if (mapping != null) {
        mapping.writeFromObjectIntoRow(domainObject,databaseRow,session,WriteType.UNDEFINED);
      }
    }
    List<Class> primaryKeyClassifications=getPrimaryKeyClassifications();
    Platform platform=session.getPlatform(domainObject.getClass());
    for (int index=0; index < size; index++) {
      Class classification=primaryKeyClassifications.get(index);
      Object value=databaseRow.get(primaryKeyFields.get(index));
      if (isPrimaryKeyComponentInvalid(value,index)) {
        if (shouldReturnNullIfNull) {
          return null;
        }
        isNull=true;
      }
      value=platform.convertObject(value,classification);
      if (cacheKeyType == CacheKeyType.ID_VALUE) {
        if (isPersistenceEntity && (!isNull)) {
          ((PersistenceEntity)domainObject)._persistence_setId(value);
        }
        return value;
      }
 else {
        primaryKeyValues[index]=value;
      }
    }
  }
  CacheId id=new CacheId(primaryKeyValues);
  if (isPersistenceEntity && (!isNull)) {
    ((PersistenceEntity)domainObject)._persistence_setId(id);
  }
  return id;
}

Fixed version (ground truth):
/** 
 * Extract primary key attribute values from the domainObject.
 */
public Object extractPrimaryKeyFromObject(Object domainObject,AbstractSession session,boolean shouldReturnNullIfNull){
  if (domainObject == null) {
    return null;
  }
  boolean isPersistenceEntity=(domainObject instanceof PersistenceEntity) && (!isXMLObjectBuilder());
  if (isPersistenceEntity) {
    Object primaryKey=((PersistenceEntity)domainObject)._persistence_getId();
    if (primaryKey != null) {
      return primaryKey;
    }
  }
  ClassDescriptor descriptor=this.descriptor;
  boolean isNull=false;
  if (descriptor.hasInheritance() && (domainObject.getClass() != descriptor.getJavaClass()) && (!domainObject.getClass().getSuperclass().equals(descriptor.getJavaClass()))) {
    return session.getDescriptor(domainObject).getObjectBuilder().extractPrimaryKeyFromObject(domainObject,session,shouldReturnNullIfNull);
  }
  CacheKeyType cacheKeyType=descriptor.getCachePolicy().getCacheKeyType();
  List<DatabaseField> primaryKeyFields=descriptor.getPrimaryKeyFields();
  Object[] primaryKeyValues=null;
  if (cacheKeyType != CacheKeyType.ID_VALUE) {
    primaryKeyValues=new Object[primaryKeyFields.size()];
  }
  List<DatabaseMapping> mappings=getPrimaryKeyMappings();
  int size=mappings.size();
  if (descriptor.hasSimplePrimaryKey()) {
    for (int index=0; index < size; index++) {
      AbstractColumnMapping mapping=(AbstractColumnMapping)mappings.get(index);
      Object keyValue=mapping.valueFromObject(domainObject,primaryKeyFields.get(index),session);
      if (isPrimaryKeyComponentInvalid(keyValue,index)) {
        if (shouldReturnNullIfNull) {
          return null;
        }
        isNull=true;
      }
      if (cacheKeyType == CacheKeyType.ID_VALUE) {
        if (isPersistenceEntity && (!isNull)) {
          ((PersistenceEntity)domainObject)._persistence_setId(keyValue);
        }
        return keyValue;
      }
 else {
        primaryKeyValues[index]=keyValue;
      }
    }
  }
 else {
    AbstractRecord databaseRow=createRecordForPKExtraction(size,session);
    Set<DatabaseMapping> writtenMappings=new HashSet<DatabaseMapping>(size);
    for (int index=0; index < size; index++) {
      DatabaseMapping mapping=mappings.get(index);
      if (mapping != null && !writtenMappings.contains(mapping)) {
        mapping.writeFromObjectIntoRow(domainObject,databaseRow,session,WriteType.UNDEFINED);
        writtenMappings.add(mapping);
      }
    }
    List<Class> primaryKeyClassifications=getPrimaryKeyClassifications();
    Platform platform=session.getPlatform(domainObject.getClass());
    for (int index=0; index < size; index++) {
      Class classification=primaryKeyClassifications.get(index);
      Object value=databaseRow.get(primaryKeyFields.get(index));
      if (isPrimaryKeyComponentInvalid(value,index)) {
        if (shouldReturnNullIfNull) {
          return null;
        }
        isNull=true;
      }
      value=platform.convertObject(value,classification);
      if (cacheKeyType == CacheKeyType.ID_VALUE) {
        if (isPersistenceEntity && (!isNull)) {
          ((PersistenceEntity)domainObject)._persistence_setId(value);
        }
        return value;
      }
 else {
        primaryKeyValues[index]=value;
      }
    }
  }
  CacheId id=new CacheId(primaryKeyValues);
  if (isPersistenceEntity && (!isNull)) {
    ((PersistenceEntity)domainObject)._persistence_setId(id);
  }
  return id;
}