Program: 19925
Project: 19925
Buggy source:
public FieldData getFieldInfo(PrestoTopic topic,PrestoFieldUsage field,boolean readOnlyMode,int offset,int limit){
  PrestoType type=field.getType();
  PrestoView parentView=field.getView();
  boolean isNewTopic=topic == null;
  String databaseId=field.getSchemaProvider().getDatabaseId();
  String topicId=isNewTopic ? "String_Node_Str" + type.getId() : topic.getId();
  String parentViewId=parentView.getId();
  String fieldId=field.getId();
  String fieldReference=databaseId + "String_Node_Str" + topicId+ "String_Node_Str"+ parentViewId+ "String_Node_Str"+ fieldId;
  FieldData fieldData=new FieldData();
  fieldData.setId(fieldId);
  fieldData.setName(field.getName());
  fieldData.setExtra(field.getExtra());
  int minCard=field.getMinCardinality();
  if (minCard > 0) {
    fieldData.setMinCardinality(minCard);
  }
  int maxCard=field.getMaxCardinality();
  if (maxCard > 0) {
    fieldData.setMaxCardinality(maxCard);
  }
  String validationType=field.getValidationType();
  if (validationType != null) {
    fieldData.setValidation(validationType);
  }
  String interfaceControl=field.getInterfaceControl();
  if (interfaceControl != null) {
    fieldData.setInterfaceControl(interfaceControl);
  }
  if (field.isEmbedded()) {
    fieldData.setEmbeddable(true);
  }
  if (field.isPageable()) {
    fieldData.setPageable(true);
  }
  boolean isReadOnly=readOnlyMode || field.isReadOnly();
  if (isReadOnly) {
    fieldData.setReadOnly(Boolean.TRUE);
  }
  List<Link> fieldLinks=new ArrayList<Link>();
  if (field.isReferenceField()) {
    fieldData.setDatatype("String_Node_Str");
    if (!isReadOnly) {
      boolean allowCreate=field.isCreatable();
      boolean allowAdd=field.isAddable();
      boolean allowRemove=field.isRemovable();
      boolean allowMove=!field.isSorted();
      if (allowCreate) {
        if (!field.getAvailableFieldCreateTypes().isEmpty()) {
          fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference));
        }
      }
      if (allowAdd) {
        if (!field.getAvailableFieldValueTypes().isEmpty()) {
          fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference));
        }
      }
      if (allowAdd || allowCreate) {
        if (!isNewTopic) {
          fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference));
          if (!field.isSorted()) {
            fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference+ "String_Node_Str"));
          }
        }
      }
      if (allowRemove && !isNewTopic) {
        fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference));
      }
      if (allowMove && !isNewTopic) {
        fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference+ "String_Node_Str"));
      }
    }
  }
 else {
    String dataType=field.getDataType();
    if (dataType != null) {
      fieldData.setDatatype(dataType);
    }
    if (!isReadOnly) {
      if (!isNewTopic) {
        fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference));
        fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference));
        if (!field.isSorted()) {
          fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference+ "String_Node_Str"));
          fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference+ "String_Node_Str"));
        }
      }
    }
  }
  if (field.isPageable()) {
    fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference+ "String_Node_Str"));
  }
  if (!fieldLinks.isEmpty()) {
    fieldData.setLinks(fieldLinks);
  }
  Collection<PrestoType> availableFieldValueTypes=field.getAvailableFieldValueTypes();
  if (!availableFieldValueTypes.isEmpty()) {
    List<TopicType> valueTypes=new ArrayList<TopicType>(availableFieldValueTypes.size());
    for (    PrestoType valueType : availableFieldValueTypes) {
      valueTypes.add(getTypeInfo(valueType));
    }
    fieldData.setValueTypes(valueTypes);
  }
  Collection<PrestoType> availableFieldCreateTypes=field.getAvailableFieldCreateTypes();
  if (!availableFieldCreateTypes.isEmpty()) {
    List<TopicType> createTypes=new ArrayList<TopicType>(availableFieldCreateTypes.size());
    for (    PrestoType createType : availableFieldCreateTypes) {
      createTypes.add(getCreateFieldInstance(topic,type,field,createType));
    }
    fieldData.setCreateTypes(createTypes);
  }
  List<? extends Object> fieldValues;
  if (isNewTopic) {
    String valuesAssignmentType=field.getValuesAssignmentType();
    if (valuesAssignmentType.equals("String_Node_Str")) {
      fieldValues=getDefaultValues(topic,type,field);
    }
 else {
      fieldValues=Collections.emptyList();
    }
  }
 else {
    if (field.isPageable() && !field.isSorted()) {
      int actualOffset=offset >= 0 ? offset : 0;
      int actualLimit=limit > 0 ? limit : DEFAULT_LIMIT;
      fieldData.setPageable(true);
      PrestoTopic.PagedValues pagedValues=topic.getValues(field,actualOffset,actualLimit);
      fieldData.setValuesOffset(pagedValues.getPaging().getOffset());
      fieldData.setValuesLimit(pagedValues.getPaging().getLimit());
      fieldData.setValuesTotal(pagedValues.getTotal());
      fieldValues=pagedValues.getValues();
    }
 else {
      fieldValues=topic.getValues(field);
    }
  }
  int size=fieldValues.size();
  int start=0;
  int end=size;
  if (field.isPageable() && field.isSorted()) {
    int _limit=limit > 0 ? limit : DEFAULT_LIMIT;
    start=Math.min(Math.max(0,offset),size);
    end=Math.min(start + _limit,size);
    fieldData.setValuesOffset(start);
    fieldData.setValuesLimit(_limit);
    fieldData.setValuesTotal(size);
  }
  if (field.isSorted()) {
    Collections.sort(fieldValues,new Comparator<Object>(){
      public int compare(      Object o1,      Object o2){
        String n1=(o1 instanceof PrestoTopic) ? ((PrestoTopic)o1).getName() : (o1 == null ? null : o1.toString());
        String n2=(o2 instanceof PrestoTopic) ? ((PrestoTopic)o2).getName() : (o2 == null ? null : o2.toString());
        return compareComparables(n1,n2);
      }
    }
);
  }
  List<Value> values=new ArrayList<Value>(fieldValues.size());
  for (int i=start; i < end; i++) {
    values.add(getValue(field,fieldValues.get(i),readOnlyMode));
  }
  fieldData.setValues(values);
  return fieldData;
}

Fixed version (ground truth):
public FieldData getFieldInfo(PrestoTopic topic,PrestoFieldUsage field,boolean readOnlyMode,int offset,int limit){
  PrestoType type=field.getType();
  PrestoView parentView=field.getView();
  boolean isNewTopic=topic == null;
  String databaseId=field.getSchemaProvider().getDatabaseId();
  String topicId=isNewTopic ? "String_Node_Str" + type.getId() : topic.getId();
  String parentViewId=parentView.getId();
  String fieldId=field.getId();
  String fieldReference=databaseId + "String_Node_Str" + topicId+ "String_Node_Str"+ parentViewId+ "String_Node_Str"+ fieldId;
  FieldData fieldData=new FieldData();
  fieldData.setId(fieldId);
  fieldData.setName(field.getName());
  fieldData.setExtra(field.getExtra());
  int minCard=field.getMinCardinality();
  if (minCard > 0) {
    fieldData.setMinCardinality(minCard);
  }
  int maxCard=field.getMaxCardinality();
  if (maxCard > 0) {
    fieldData.setMaxCardinality(maxCard);
  }
  String validationType=field.getValidationType();
  if (validationType != null) {
    fieldData.setValidation(validationType);
  }
  String interfaceControl=field.getInterfaceControl();
  if (interfaceControl != null) {
    fieldData.setInterfaceControl(interfaceControl);
  }
  if (field.isEmbedded()) {
    fieldData.setEmbeddable(true);
  }
  if (field.isPageable()) {
    fieldData.setPageable(true);
  }
  boolean isReadOnly=readOnlyMode || field.isReadOnly();
  if (isReadOnly) {
    fieldData.setReadOnly(Boolean.TRUE);
  }
  List<Link> fieldLinks=new ArrayList<Link>();
  if (field.isReferenceField()) {
    fieldData.setDatatype("String_Node_Str");
    if (!isReadOnly) {
      boolean allowCreate=field.isCreatable();
      boolean allowAdd=field.isAddable();
      boolean allowRemove=field.isRemovable();
      boolean allowMove=!field.isSorted();
      if (allowCreate) {
        if (!field.getAvailableFieldCreateTypes().isEmpty()) {
          fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference));
        }
      }
      if (allowAdd) {
        if (!field.getAvailableFieldValueTypes().isEmpty()) {
          fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference));
        }
      }
      if (allowAdd || allowCreate) {
        if (!isNewTopic) {
          fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference));
          if (!field.isSorted()) {
            fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference+ "String_Node_Str"));
          }
        }
      }
      if (allowRemove && !isNewTopic) {
        fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference));
      }
      if (allowMove && !isNewTopic) {
        fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference+ "String_Node_Str"));
      }
    }
  }
 else {
    String dataType=field.getDataType();
    if (dataType != null) {
      fieldData.setDatatype(dataType);
    }
    if (!isReadOnly) {
      if (!isNewTopic) {
        fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference));
        fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference));
        if (!field.isSorted()) {
          fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference+ "String_Node_Str"));
          fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference+ "String_Node_Str"));
        }
      }
    }
  }
  if (field.isPageable()) {
    fieldLinks.add(new Link("String_Node_Str",uriInfo.getBaseUri() + "String_Node_Str" + fieldReference+ "String_Node_Str"));
  }
  if (!fieldLinks.isEmpty()) {
    fieldData.setLinks(fieldLinks);
  }
  Collection<PrestoType> availableFieldValueTypes=field.getAvailableFieldValueTypes();
  if (!availableFieldValueTypes.isEmpty()) {
    List<TopicType> valueTypes=new ArrayList<TopicType>(availableFieldValueTypes.size());
    for (    PrestoType valueType : availableFieldValueTypes) {
      valueTypes.add(getTypeInfo(valueType));
    }
    fieldData.setValueTypes(valueTypes);
  }
  Collection<PrestoType> availableFieldCreateTypes=field.getAvailableFieldCreateTypes();
  if (!availableFieldCreateTypes.isEmpty()) {
    List<TopicType> createTypes=new ArrayList<TopicType>(availableFieldCreateTypes.size());
    for (    PrestoType createType : availableFieldCreateTypes) {
      createTypes.add(getCreateFieldInstance(topic,type,field,createType));
    }
    fieldData.setCreateTypes(createTypes);
  }
  List<? extends Object> fieldValues;
  if (isNewTopic) {
    String valuesAssignmentType=field.getValuesAssignmentType();
    if (valuesAssignmentType.equals("String_Node_Str")) {
      fieldValues=getDefaultValues(topic,type,field);
    }
 else {
      fieldValues=Collections.emptyList();
    }
  }
 else {
    if (field.isPageable() && !field.isSorted()) {
      int actualOffset=offset >= 0 ? offset : 0;
      int actualLimit=limit > 0 ? limit : DEFAULT_LIMIT;
      fieldData.setPageable(true);
      PrestoTopic.PagedValues pagedValues=topic.getValues(field,actualOffset,actualLimit);
      fieldData.setValuesOffset(pagedValues.getPaging().getOffset());
      fieldData.setValuesLimit(pagedValues.getPaging().getLimit());
      fieldData.setValuesTotal(pagedValues.getTotal());
      fieldValues=pagedValues.getValues();
    }
 else {
      fieldValues=topic.getValues(field);
    }
  }
  int size=fieldValues.size();
  int start=0;
  int end=size;
  if (field.isSorted()) {
    Collections.sort(fieldValues,new Comparator<Object>(){
      public int compare(      Object o1,      Object o2){
        String n1=(o1 instanceof PrestoTopic) ? ((PrestoTopic)o1).getName() : (o1 == null ? null : o1.toString());
        String n2=(o2 instanceof PrestoTopic) ? ((PrestoTopic)o2).getName() : (o2 == null ? null : o2.toString());
        return compareComparables(n1,n2);
      }
    }
);
  }
  List<Value> values=new ArrayList<Value>(fieldValues.size());
  for (int i=start; i < end; i++) {
    Object value=fieldValues.get(i);
    if (value != null) {
      values.add(getValue(field,value,readOnlyMode));
    }
 else {
      size--;
    }
  }
  fieldData.setValues(values);
  if (field.isPageable() && field.isSorted()) {
    int _limit=limit > 0 ? limit : DEFAULT_LIMIT;
    start=Math.min(Math.max(0,offset),size);
    end=Math.min(start + _limit,size);
    fieldData.setValuesOffset(start);
    fieldData.setValuesLimit(_limit);
    fieldData.setValuesTotal(size);
  }
  return fieldData;
}