Program: 66576
Project: 66576
Buggy source:
/** 
 * INTERNAL: Post initializations after mappings are initialized.
 */
public void postInitialize(AbstractSession session) throws DescriptorException {
  if (isInitialized(POST_INITIALIZED) || isInvalid()) {
    return;
  }
  setInitializationStage(POST_INITIALIZED);
  if (hasInheritance()) {
    for (    ClassDescriptor child : getInheritancePolicy().getChildDescriptors()) {
      child.postInitialize(session);
    }
  }
  for (  DatabaseMapping mapping : getMappings()) {
    mapping.postInitialize(session);
    if (!shouldAcquireCascadedLocks()) {
      if ((mapping instanceof ForeignReferenceMapping) && (!((ForeignReferenceMapping)mapping).usesIndirection())) {
        setShouldAcquireCascadedLocks(true);
      }
      if ((mapping instanceof AggregateObjectMapping) && mapping.getReferenceDescriptor().shouldAcquireCascadedLocks()) {
        setShouldAcquireCascadedLocks(true);
      }
    }
  }
  if (hasInheritance()) {
    getInheritancePolicy().postInitialize(session);
  }
  for (int index=(getPrimaryKeyFields().size() - 1); index >= 0; index--) {
    DatabaseField primaryKeyField=getPrimaryKeyFields().get(index);
    int fieldIndex=getFields().indexOf(primaryKeyField);
    if (fieldIndex != -1) {
      primaryKeyField=getFields().get(fieldIndex);
      getPrimaryKeyFields().set(index,primaryKeyField);
    }
  }
  for (int index=0; index < getFields().size(); index++) {
    DatabaseField field=getFields().elementAt(index);
    if (field.getType() == null) {
      DatabaseMapping mapping=getObjectBuilder().getMappingForField(field);
      if (mapping != null) {
        field.setType(mapping.getFieldClassification(field));
      }
    }
    field.setIndex(index);
  }
  if (getCacheKeyType() == null) {
    if ((getPrimaryKeyFields().size() > 1) || getObjectBuilder().isXMLObjectBuilder()) {
      setCacheKeyType(CacheKeyType.CACHE_ID);
    }
 else     if (getPrimaryKeyFields().size() == 1) {
      Class type=getObjectBuilder().getFieldClassification(getPrimaryKeyFields().get(0));
      if ((type == null) || type.isArray()) {
        setCacheKeyType(CacheKeyType.CACHE_ID);
      }
 else {
        setCacheKeyType(CacheKeyType.ID_VALUE);
      }
    }
 else {
      setCacheKeyType(CacheKeyType.CACHE_ID);
    }
  }
  getObjectBuilder().postInitialize(session);
  validateAfterInitialization(session);
  checkDatabase(session);
}

Fixed version (ground truth):
/** 
 * INTERNAL: Post initializations after mappings are initialized.
 */
public void postInitialize(AbstractSession session) throws DescriptorException {
  if (isInitialized(POST_INITIALIZED) || isInvalid()) {
    return;
  }
  setInitializationStage(POST_INITIALIZED);
  if (hasInheritance()) {
    for (    ClassDescriptor child : getInheritancePolicy().getChildDescriptors()) {
      child.postInitialize(session);
    }
  }
  for (  DatabaseMapping mapping : getMappings()) {
    mapping.postInitialize(session);
    if (!shouldAcquireCascadedLocks()) {
      if ((mapping instanceof ForeignReferenceMapping) && (!((ForeignReferenceMapping)mapping).usesIndirection())) {
        setShouldAcquireCascadedLocks(true);
      }
      if ((mapping instanceof AggregateObjectMapping) && mapping.getReferenceDescriptor().shouldAcquireCascadedLocks()) {
        setShouldAcquireCascadedLocks(true);
      }
    }
  }
  if (hasInheritance()) {
    getInheritancePolicy().postInitialize(session);
  }
  for (int index=(getPrimaryKeyFields().size() - 1); index >= 0; index--) {
    DatabaseField primaryKeyField=getPrimaryKeyFields().get(index);
    int fieldIndex=getFields().indexOf(primaryKeyField);
    if (fieldIndex != -1) {
      primaryKeyField=getFields().get(fieldIndex);
      getPrimaryKeyFields().set(index,primaryKeyField);
    }
  }
  for (int index=0; index < getFields().size(); index++) {
    DatabaseField field=getFields().elementAt(index);
    if (field.getType() == null) {
      DatabaseMapping mapping=getObjectBuilder().getMappingForField(field);
      if (mapping != null) {
        field.setType(mapping.getFieldClassification(field));
      }
    }
    field.setIndex(index);
  }
  if (getCacheKeyType() == null || (getCacheKeyType() == CacheKeyType.AUTO)) {
    if ((getPrimaryKeyFields().size() > 1) || getObjectBuilder().isXMLObjectBuilder()) {
      setCacheKeyType(CacheKeyType.CACHE_ID);
    }
 else     if (getPrimaryKeyFields().size() == 1) {
      Class type=getObjectBuilder().getFieldClassification(getPrimaryKeyFields().get(0));
      if ((type == null) || type.isArray()) {
        setCacheKeyType(CacheKeyType.CACHE_ID);
      }
 else {
        setCacheKeyType(CacheKeyType.ID_VALUE);
      }
    }
 else {
      setCacheKeyType(CacheKeyType.CACHE_ID);
    }
  }
 else   if ((getCacheKeyType() == CacheKeyType.ID_VALUE) && (getPrimaryKeyFields().size() > 1)) {
    session.getIntegrityChecker().handleError(DescriptorException.cannotUseIdValueForCompositeId(this));
  }
  getObjectBuilder().postInitialize(session);
  validateAfterInitialization(session);
  checkDatabase(session);
}