Program: 65796
Project: 65796
Buggy source:
private Object getValue(AbstractSession session,Reference reference,CacheId primaryKey){
  Class referenceTargetClass=reference.getTargetClass();
  if (null == referenceTargetClass || referenceTargetClass == ClassConstants.OBJECT) {
    for (    Object entry : session.getDescriptors().values()) {
      Object value=null;
      XMLDescriptor targetDescriptor=(XMLDescriptor)entry;
      List pkFields=targetDescriptor.getPrimaryKeyFields();
      if (1 == pkFields.size()) {
        XMLField pkField=(XMLField)pkFields.get(0);
        pkField=(XMLField)targetDescriptor.getTypedField(pkField);
        Class targetType=pkField.getType();
        if (targetType == ClassConstants.STRING || targetType == ClassConstants.OBJECT) {
          value=session.getIdentityMapAccessor().getFromIdentityMap(primaryKey,targetDescriptor.getJavaClass());
        }
 else {
          try {
            Object[] pkValues=primaryKey.getPrimaryKey();
            Object[] convertedPkValues=new Object[pkValues.length];
            for (int x=0; x < pkValues.length; x++) {
              convertedPkValues[x]=session.getDatasourcePlatform().getConversionManager().convertObject(pkValues[x],targetType);
            }
            value=session.getIdentityMapAccessor().getFromIdentityMap(new CacheId(convertedPkValues),targetDescriptor.getJavaClass());
          }
 catch (          ConversionException e) {
          }
        }
        if (null != value) {
          return value;
        }
      }
    }
    return null;
  }
 else {
    return session.getIdentityMapAccessor().getFromIdentityMap(primaryKey,referenceTargetClass);
  }
}

Fixed version (ground truth):
private Object getValue(AbstractSession session,Reference reference,CacheId primaryKey){
  Class referenceTargetClass=reference.getTargetClass();
  if (null == referenceTargetClass || referenceTargetClass == ClassConstants.OBJECT) {
    for (    Object entry : session.getDescriptors().values()) {
      Object value=null;
      XMLDescriptor targetDescriptor=(XMLDescriptor)entry;
      List pkFields=targetDescriptor.getPrimaryKeyFields();
      if (null != pkFields && 1 == pkFields.size()) {
        XMLField pkField=(XMLField)pkFields.get(0);
        pkField=(XMLField)targetDescriptor.getTypedField(pkField);
        Class targetType=pkField.getType();
        if (targetType == ClassConstants.STRING || targetType == ClassConstants.OBJECT) {
          value=session.getIdentityMapAccessor().getFromIdentityMap(primaryKey,targetDescriptor.getJavaClass());
        }
 else {
          try {
            Object[] pkValues=primaryKey.getPrimaryKey();
            Object[] convertedPkValues=new Object[pkValues.length];
            for (int x=0; x < pkValues.length; x++) {
              convertedPkValues[x]=session.getDatasourcePlatform().getConversionManager().convertObject(pkValues[x],targetType);
            }
            value=session.getIdentityMapAccessor().getFromIdentityMap(new CacheId(convertedPkValues),targetDescriptor.getJavaClass());
          }
 catch (          ConversionException e) {
          }
        }
        if (null != value) {
          return value;
        }
      }
    }
    return null;
  }
 else {
    return session.getIdentityMapAccessor().getFromIdentityMap(primaryKey,referenceTargetClass);
  }
}