Program: 168785
Project: 168785
Buggy source:
public static Class<?> resolveFieldClass(Class<?> baseClass,Attribute<?,?> attr){
  Class<?> resolverBaseClass=getConcreterClass(baseClass,attr.getDeclaringType().getJavaType());
  Class<?> jpaReportedFieldClass;
  Class<?> fieldClass;
  if (attr.isCollection()) {
    PluralAttribute<?,?,?> collectionAttr=(PluralAttribute<?,?,?>)attr;
    fieldClass=collectionAttr.getElementType().getJavaType();
    jpaReportedFieldClass=fieldClass;
    if (collectionAttr.getCollectionType() == PluralAttribute.CollectionType.MAP) {
      if (attr.getJavaMember() instanceof Method) {
        Method method=(Method)attr.getJavaMember();
        Class<?>[] typeArguments=ReflectionUtils.getResolvedMethodReturnTypeArguments(resolverBaseClass,method);
        if (typeArguments.length != 0) {
          fieldClass=typeArguments[1];
          if (fieldClass == null) {
            fieldClass=resolveType(resolverBaseClass,((ParameterizedType)method.getGenericReturnType()).getActualTypeArguments()[1]);
          }
        }
      }
 else {
        Field field=(Field)attr.getJavaMember();
        Class<?>[] typeArguments=ReflectionUtils.getResolvedFieldTypeArguments(resolverBaseClass,field);
        if (typeArguments.length != 0) {
          fieldClass=typeArguments[1];
          if (fieldClass == null) {
            fieldClass=resolveType(resolverBaseClass,((ParameterizedType)field.getGenericType()).getActualTypeArguments()[1]);
          }
        }
      }
    }
 else {
      if (attr.getJavaMember() instanceof Method) {
        Method method=(Method)attr.getJavaMember();
        Class<?>[] typeArguments=ReflectionUtils.getResolvedMethodReturnTypeArguments(resolverBaseClass,method);
        if (typeArguments.length != 0) {
          fieldClass=typeArguments[0];
          if (fieldClass == null) {
            fieldClass=resolveType(resolverBaseClass,((ParameterizedType)method.getGenericReturnType()).getActualTypeArguments()[0]);
          }
        }
      }
 else {
        Field field=(Field)attr.getJavaMember();
        Class<?>[] typeArguments=ReflectionUtils.getResolvedFieldTypeArguments(resolverBaseClass,field);
        if (typeArguments.length != 0) {
          fieldClass=typeArguments[0];
          if (fieldClass == null) {
            fieldClass=resolveType(resolverBaseClass,((ParameterizedType)field.getGenericType()).getActualTypeArguments()[0]);
          }
        }
      }
    }
  }
 else {
    jpaReportedFieldClass=attr.getJavaType();
    if (attr.getJavaMember() instanceof Method) {
      Method method=(Method)attr.getJavaMember();
      fieldClass=ReflectionUtils.getResolvedMethodReturnType(resolverBaseClass,method);
      if (fieldClass == null) {
        fieldClass=resolveType(resolverBaseClass,method.getGenericReturnType());
      }
      if (fieldClass.isAssignableFrom(jpaReportedFieldClass)) {
        return jpaReportedFieldClass;
      }
 else       if (jpaReportedFieldClass.isAssignableFrom(fieldClass)) {
        return fieldClass;
      }
 else       if (method.getGenericReturnType() instanceof TypeVariable<?>) {
        return fieldClass;
      }
    }
 else {
      Field field=(Field)attr.getJavaMember();
      fieldClass=ReflectionUtils.getResolvedFieldType(resolverBaseClass,field);
      if (fieldClass == null) {
        fieldClass=resolveType(resolverBaseClass,field.getGenericType());
      }
      if (fieldClass.isAssignableFrom(jpaReportedFieldClass)) {
        return jpaReportedFieldClass;
      }
 else       if (jpaReportedFieldClass.isAssignableFrom(fieldClass)) {
        return fieldClass;
      }
 else       if (field.getGenericType() instanceof TypeVariable<?>) {
        return fieldClass;
      }
    }
  }
  return getConcreterClass(fieldClass,jpaReportedFieldClass);
}

Fixed version (ground truth):
public static Class<?> resolveFieldClass(Class<?> baseClass,Attribute<?,?> attr){
  Class<?> resolverBaseClass=getConcreterClass(baseClass,attr.getDeclaringType().getJavaType());
  Class<?> jpaReportedFieldClass;
  Class<?> fieldClass;
  if (attr.isCollection()) {
    PluralAttribute<?,?,?> collectionAttr=(PluralAttribute<?,?,?>)attr;
    fieldClass=collectionAttr.getElementType().getJavaType();
    jpaReportedFieldClass=fieldClass;
    if (collectionAttr.getCollectionType() == PluralAttribute.CollectionType.MAP) {
      if (attr.getJavaMember() instanceof Method) {
        Method method=(Method)attr.getJavaMember();
        Class<?>[] typeArguments=ReflectionUtils.getResolvedMethodReturnTypeArguments(resolverBaseClass,method);
        if (typeArguments.length != 0) {
          fieldClass=typeArguments[1];
          if (fieldClass == null) {
            fieldClass=resolveType(resolverBaseClass,((ParameterizedType)method.getGenericReturnType()).getActualTypeArguments()[1]);
          }
        }
      }
 else {
        Field field=(Field)attr.getJavaMember();
        Class<?>[] typeArguments=ReflectionUtils.getResolvedFieldTypeArguments(resolverBaseClass,field);
        if (typeArguments.length != 0) {
          fieldClass=typeArguments[1];
          if (fieldClass == null) {
            fieldClass=resolveType(resolverBaseClass,((ParameterizedType)field.getGenericType()).getActualTypeArguments()[1]);
          }
        }
      }
    }
 else {
      if (attr.getJavaMember() instanceof Method) {
        Method method=(Method)attr.getJavaMember();
        Class<?>[] typeArguments=ReflectionUtils.getResolvedMethodReturnTypeArguments(resolverBaseClass,method);
        if (typeArguments.length != 0) {
          fieldClass=typeArguments[0];
          if (fieldClass == null) {
            fieldClass=resolveType(resolverBaseClass,((ParameterizedType)method.getGenericReturnType()).getActualTypeArguments()[0]);
          }
        }
      }
 else {
        Field field=(Field)attr.getJavaMember();
        Class<?>[] typeArguments=ReflectionUtils.getResolvedFieldTypeArguments(resolverBaseClass,field);
        if (typeArguments.length != 0) {
          fieldClass=typeArguments[0];
          if (fieldClass == null) {
            fieldClass=resolveType(resolverBaseClass,((ParameterizedType)field.getGenericType()).getActualTypeArguments()[0]);
          }
        }
      }
    }
  }
 else {
    jpaReportedFieldClass=attr.getJavaType();
    if (attr.getJavaMember() instanceof Method) {
      Method method=(Method)attr.getJavaMember();
      fieldClass=ReflectionUtils.getResolvedMethodReturnType(resolverBaseClass,method);
      if (fieldClass == null) {
        fieldClass=resolveType(resolverBaseClass,method.getGenericReturnType());
      }
      if (fieldClass.isAssignableFrom(jpaReportedFieldClass)) {
        return jpaReportedFieldClass;
      }
 else       if (jpaReportedFieldClass.isAssignableFrom(fieldClass)) {
        return fieldClass;
      }
 else       if (method.getGenericReturnType() instanceof TypeVariable<?>) {
        return fieldClass;
      }
    }
 else {
      Field field=(Field)attr.getJavaMember();
      fieldClass=ReflectionUtils.getResolvedFieldType(resolverBaseClass,field);
      if (fieldClass == null) {
        fieldClass=resolveType(resolverBaseClass,field.getGenericType());
      }
      if (fieldClass.isAssignableFrom(jpaReportedFieldClass)) {
        return jpaReportedFieldClass;
      }
 else       if (jpaReportedFieldClass.isAssignableFrom(fieldClass)) {
        return fieldClass;
      }
 else       if (field.getGenericType() instanceof TypeVariable<?>) {
        return fieldClass;
      }
    }
  }
  if (fieldClass.isAssignableFrom(jpaReportedFieldClass)) {
    return jpaReportedFieldClass;
  }
 else   if (jpaReportedFieldClass.isAssignableFrom(fieldClass)) {
    return fieldClass;
  }
 else {
    return fieldClass;
  }
}