Program: 146022
Project: 146022
Buggy source:
@Override public void validate(final ValidationHandler handler){
  int errorCount=handler.getErrorCount();
  fieldType.validate(handler);
  if (handler.getErrorCount() > errorCount) {
    return;
  }
  TypeMetadata currentType=fieldType;
  if (!XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(currentType.getNamespace())) {
    while (!currentType.getSuperTypes().isEmpty()) {
      TypeMetadata superType=currentType.getSuperTypes().iterator().next();
      if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(superType.getNamespace()) && ("String_Node_Str".equals(superType.getName()) || "String_Node_Str".equals(superType.getName()))) {
        break;
      }
      currentType=superType;
      errorCount=handler.getErrorCount();
      currentType.validate(handler);
      if (handler.getErrorCount() > errorCount) {
        return;
      }
    }
  }
  final Integer line=this.getData(MetadataRepository.XSD_LINE_NUMBER);
  final Integer column=this.getData(MetadataRepository.XSD_COLUMN_NUMBER);
  final Element xmlElement=this.getData(MetadataRepository.XSD_DOM_ELEMENT);
  if (!Types.STRING.equals(currentType.getName())) {
    handler.error(this,"String_Node_Str" + getName() + "String_Node_Str",xmlElement,line,column,ValidationError.FOREIGN_KEY_NOT_STRING_TYPED);
  }
  if (fieldType.freeze(handler).getData(MetadataRepository.DATA_MAX_LENGTH) != null) {
    handler.warning(this,"String_Node_Str" + getName() + "String_Node_Str",xmlElement,line,column,ValidationError.FOREIGN_KEY_USES_MAX_LENGTH);
  }
  int previousErrorCount=handler.getErrorCount();
  referencedField.validate(new LocationOverride(this,handler,xmlElement,line,column));
  if (handler.getErrorCount() > previousErrorCount) {
    return;
  }
  for (  FieldMetadata foreignKeyInfo : foreignKeyInfoFields) {
    errorCount=handler.getErrorCount();
    foreignKeyInfo.validate(handler);
    if (handler.getErrorCount() > errorCount) {
      continue;
    }
    if (!isPrimitiveTypeField(foreignKeyInfo)) {
      handler.warning(foreignKeyInfo,"String_Node_Str",foreignKeyInfo.<Element>getData(MetadataRepository.XSD_DOM_ELEMENT),foreignKeyInfo.<Integer>getData(MetadataRepository.XSD_LINE_NUMBER),foreignKeyInfo.<Integer>getData(MetadataRepository.XSD_COLUMN_NUMBER),ValidationError.FOREIGN_KEY_INFO_NOT_PRIMITIVE_XSD_TYPED);
    }
    if (foreignKeyInfo.isMany()) {
      handler.warning(foreignKeyInfo,"String_Node_Str",foreignKeyInfo.<Element>getData(MetadataRepository.XSD_DOM_ELEMENT),foreignKeyInfo.<Integer>getData(MetadataRepository.XSD_LINE_NUMBER),foreignKeyInfo.<Integer>getData(MetadataRepository.XSD_COLUMN_NUMBER),ValidationError.FOREIGN_KEY_INFO_REPEATABLE);
    }
  }
  freeze(handler);
  if (!referencedField.isKey()) {
    StringBuilder referencedTypePK=new StringBuilder();
    Iterator<FieldMetadata> keyFields=referencedType.getKeyFields().iterator();
    while (keyFields.hasNext()) {
      referencedTypePK.append('\'').append(keyFields.next().getName()).append('\'');
      if (keyFields.hasNext()) {
        referencedTypePK.append(' ');
      }
    }
    handler.warning(referencedField,"String_Node_Str" + referencedTypePK + "String_Node_Str",this.<Element>getData(MetadataRepository.XSD_DOM_ELEMENT),this.<Integer>getData(MetadataRepository.XSD_LINE_NUMBER),this.<Integer>getData(MetadataRepository.XSD_COLUMN_NUMBER),ValidationError.FOREIGN_KEY_SHOULD_POINT_TO_PRIMARY_KEY);
  }
}

Fixed version (ground truth):
@Override public void validate(final ValidationHandler handler){
  int errorCount=handler.getErrorCount();
  fieldType.validate(handler);
  if (handler.getErrorCount() > errorCount) {
    return;
  }
  TypeMetadata currentType=fieldType;
  if (!XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(currentType.getNamespace())) {
    while (!currentType.getSuperTypes().isEmpty()) {
      TypeMetadata superType=currentType.getSuperTypes().iterator().next();
      if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(superType.getNamespace()) && ("String_Node_Str".equals(superType.getName()) || "String_Node_Str".equals(superType.getName()))) {
        break;
      }
      currentType=superType;
      errorCount=handler.getErrorCount();
      currentType.validate(handler);
      if (handler.getErrorCount() > errorCount) {
        return;
      }
    }
  }
  final Integer line=this.getData(MetadataRepository.XSD_LINE_NUMBER);
  final Integer column=this.getData(MetadataRepository.XSD_COLUMN_NUMBER);
  final Element xmlElement=this.getData(MetadataRepository.XSD_DOM_ELEMENT);
  if (!Types.STRING.equals(currentType.getName())) {
    handler.error(this,"String_Node_Str" + getName() + "String_Node_Str",xmlElement,line,column,ValidationError.FOREIGN_KEY_NOT_STRING_TYPED);
  }
  if (fieldType.freeze(handler).getData(MetadataRepository.DATA_MAX_LENGTH) != null) {
    handler.warning(this,"String_Node_Str" + getName() + "String_Node_Str",xmlElement,line,column,ValidationError.FOREIGN_KEY_USES_MAX_LENGTH);
  }
  int previousErrorCount=handler.getErrorCount();
  referencedField.validate(new LocationOverride(this,handler,xmlElement,line,column));
  if (handler.getErrorCount() > previousErrorCount) {
    return;
  }
  for (  FieldMetadata foreignKeyInfo : foreignKeyInfoFields) {
    errorCount=handler.getErrorCount();
    foreignKeyInfo.validate(handler);
    if (handler.getErrorCount() > errorCount) {
      continue;
    }
    if (!isPrimitiveTypeField(foreignKeyInfo)) {
      handler.warning(foreignKeyInfo,"String_Node_Str",foreignKeyInfo.<Element>getData(MetadataRepository.XSD_DOM_ELEMENT),foreignKeyInfo.<Integer>getData(MetadataRepository.XSD_LINE_NUMBER),foreignKeyInfo.<Integer>getData(MetadataRepository.XSD_COLUMN_NUMBER),ValidationError.FOREIGN_KEY_INFO_NOT_PRIMITIVE_XSD_TYPED);
    }
    if (foreignKeyInfo.isMany()) {
      handler.warning(foreignKeyInfo,"String_Node_Str",foreignKeyInfo.<Element>getData(MetadataRepository.XSD_DOM_ELEMENT),foreignKeyInfo.<Integer>getData(MetadataRepository.XSD_LINE_NUMBER),foreignKeyInfo.<Integer>getData(MetadataRepository.XSD_COLUMN_NUMBER),ValidationError.FOREIGN_KEY_INFO_REPEATABLE);
    }
    if (foreignKeyInfo.getContainingType() != null) {
      ComplexTypeMetadata foreignKeyInfoContainingType=foreignKeyInfo.freeze(handler).getContainingType();
      while (foreignKeyInfoContainingType instanceof ContainedComplexTypeMetadata) {
        foreignKeyInfoContainingType=((ContainedComplexTypeMetadata)foreignKeyInfoContainingType).getContainerType();
      }
      if (foreignKeyInfoContainingType.isInstantiable() && !foreignKeyInfoContainingType.equals(referencedType)) {
        handler.error(foreignKeyInfo,"String_Node_Str",foreignKeyInfo.<Element>getData(MetadataRepository.XSD_DOM_ELEMENT),foreignKeyInfo.<Integer>getData(MetadataRepository.XSD_LINE_NUMBER),foreignKeyInfo.<Integer>getData(MetadataRepository.XSD_COLUMN_NUMBER),ValidationError.FOREIGN_KEY_INFO_NOT_REFERENCING_FK_TYPE);
      }
    }
  }
  freeze(handler);
  if (!referencedField.isKey()) {
    StringBuilder referencedTypePK=new StringBuilder();
    Iterator<FieldMetadata> keyFields=referencedType.getKeyFields().iterator();
    while (keyFields.hasNext()) {
      referencedTypePK.append('\'').append(keyFields.next().getName()).append('\'');
      if (keyFields.hasNext()) {
        referencedTypePK.append(' ');
      }
    }
    handler.warning(referencedField,"String_Node_Str" + referencedTypePK + "String_Node_Str",this.<Element>getData(MetadataRepository.XSD_DOM_ELEMENT),this.<Integer>getData(MetadataRepository.XSD_LINE_NUMBER),this.<Integer>getData(MetadataRepository.XSD_COLUMN_NUMBER),ValidationError.FOREIGN_KEY_SHOULD_POINT_TO_PRIMARY_KEY);
  }
}