Program: 19913
Project: 19913
Buggy source:
private List<? extends Object> updateAndExtractValuesFromFieldData(PrestoContextRules rules,PrestoFieldUsage field,FieldData fieldData,boolean resolveEmbedded,boolean includeExisting,boolean filterNonStorable,boolean validateValueTypes){
  Collection<Value> values=fieldData.getValues();
  List<Object> result=new ArrayList<Object>(values.size());
  if (!values.isEmpty()) {
    PrestoContext context=rules.getContext();
    if (field.isReferenceField()) {
      if (field.isInline()) {
        List<Object> newValues=new ArrayList<Object>();
        for (        Value value : values) {
          TopicView embeddedTopic=getEmbeddedTopic(value);
          if (embeddedTopic != null) {
            boolean filterNonStorableNested=true;
            newValues.add(buildInlineTopic(context,field,embeddedTopic,filterNonStorableNested,validateValueTypes));
          }
 else {
            String typeId=value.getType();
            PrestoType type=schemaProvider.getTypeById(typeId,null);
            if (type != null) {
              newValues.add(buildInlineTopic(context,type,value.getValue()));
            }
 else {
              throw new InvalidValueTypeConstraintException(getSchemaProvider());
            }
          }
        }
        if (context.isNewTopic()) {
          result.addAll(newValues);
        }
 else {
          PrestoTopic topic=context.getTopic();
          List<? extends Object> existingValues=topic.getValues(field);
          result.addAll(mergeInlineTopics(newValues,existingValues,includeExisting));
        }
      }
 else {
        List<String> valueIds=new ArrayList<String>(values.size());
        for (        Value value : values) {
          TopicView embeddedTopic=getEmbeddedTopic(value);
          if (resolveEmbedded && embeddedTopic != null) {
            result.add(updateEmbeddedTopic(rules,field,embeddedTopic));
          }
 else {
            String valueId=getReferenceValue(value);
            if (valueId != null) {
              valueIds.add(valueId);
            }
          }
        }
        if (!valueIds.isEmpty()) {
          result.addAll(getDataProvider().getTopicsByIds(valueIds));
        }
      }
      if (validateValueTypes) {
        validateValueTypes(context,field,result);
      }
    }
 else {
      for (      Value value : values) {
        result.add(getPrimitiveValue(value));
      }
    }
    if (filterNonStorable) {
      removeNonStorableFieldValues(rules,field,result);
    }
  }
  return result;
}

Fixed version (ground truth):
private List<? extends Object> updateAndExtractValuesFromFieldData(PrestoContextRules rules,PrestoFieldUsage field,FieldData fieldData,boolean resolveEmbedded,boolean includeExisting,boolean filterNonStorable,boolean validateValueTypes){
  Collection<Value> values=fieldData.getValues();
  List<Object> result=new ArrayList<Object>(values.size());
  if (!values.isEmpty()) {
    PrestoContext context=rules.getContext();
    if (field.isReferenceField()) {
      if (field.isInline()) {
        List<Object> newValues=new ArrayList<Object>();
        for (        Value value : values) {
          TopicView embeddedTopic=getEmbeddedTopic(value);
          if (embeddedTopic != null) {
            boolean filterNonStorableNested=true;
            newValues.add(buildInlineTopic(context,field,embeddedTopic,filterNonStorableNested,validateValueTypes));
          }
 else {
            String typeId=value.getType();
            PrestoType type=schemaProvider.getTypeById(typeId,null);
            if (type != null) {
              newValues.add(buildInlineTopic(context,type,value.getValue()));
            }
 else {
              throw new InvalidValueTypeConstraintException(getSchemaProvider());
            }
          }
        }
        if (context.isNewTopic()) {
          result.addAll(newValues);
        }
 else {
          PrestoTopic topic=context.getTopic();
          List<? extends Object> existingValues=topic.getValues(field);
          result.addAll(mergeInlineTopics(newValues,existingValues,includeExisting));
        }
      }
 else {
        List<String> valueIds=new ArrayList<String>(values.size());
        for (        Value value : values) {
          TopicView embeddedTopic=getEmbeddedTopic(value);
          if (resolveEmbedded && embeddedTopic != null) {
            result.add(updateEmbeddedTopic(rules,field,embeddedTopic));
          }
 else {
            String valueId=getReferenceValue(value);
            if (valueId != null) {
              valueIds.add(valueId);
            }
          }
        }
        if (!valueIds.isEmpty()) {
          result.addAll(getDataProvider().getTopicsByIds(valueIds));
        }
      }
      if (validateValueTypes) {
        validateValueTypes(context,field,result);
      }
    }
 else {
      for (      Value value : values) {
        result.add(getPrimitiveValue(value));
      }
    }
    if (filterNonStorable) {
      filterNonStorableFieldValues(rules,field,result);
    }
  }
  return result;
}