Program: 59609
Project: 59609
Buggy source:
private static void resolve(EdmDataServices metadata){
  final Map<String,EdmEntityType> allEetsByFQName=Enumerable.create(metadata.getEntityTypes()).toMap(new Func1<EdmEntityType,String>(){
    public String apply(    EdmEntityType input){
      return input.getFQAliasName() != null ? input.getFQAliasName() : input.getFullyQualifiedTypeName();
    }
  }
);
  final Map<String,EdmAssociation> allEasByFQName=Enumerable.create(metadata.getAssociations()).toMap(new Func1<EdmAssociation,String>(){
    public String apply(    EdmAssociation input){
      return input.getFQAliasName() != null ? input.getFQAliasName() : input.getFQNamespaceName();
    }
  }
);
  for (  EdmSchema edmSchema : metadata.getSchemas()) {
    for (int i=0; i < edmSchema.associations.size(); i++) {
      EdmAssociation tmpAssociation=edmSchema.associations.get(i);
      List<EdmAssociationEnd> finalEnds=Enumerable.create(tmpAssociation.end1,tmpAssociation.end2).select(new Func1<EdmAssociationEnd,EdmAssociationEnd>(){
        public EdmAssociationEnd apply(        final EdmAssociationEnd tempEnd){
          EdmEntityType eet=allEetsByFQName.get(((TempEdmAssociationEnd)tempEnd).typeName);
          return new EdmAssociationEnd(tempEnd.role,eet,tempEnd.multiplicity);
        }
      }
).toList();
      EdmAssociation ea=new EdmAssociation(tmpAssociation.namespace,tmpAssociation.alias,tmpAssociation.name,finalEnds.get(0),finalEnds.get(1));
      edmSchema.associations.set(i,ea);
      allEasByFQName.put(ea.getFQAliasName() != null ? ea.getFQAliasName() : ea.getFQNamespaceName(),ea);
    }
    for (    EdmEntityType eet : edmSchema.entityTypes) {
      List<EdmNavigationProperty> navProps=eet.getDeclaredNavigationProperties().toList();
      for (int i=0; i < navProps.size(); i++) {
        final TempEdmNavigationProperty tmp=(TempEdmNavigationProperty)navProps.get(i);
        final EdmAssociation ea=allEasByFQName.get(tmp.relationshipName);
        List<EdmAssociationEnd> finalEnds=Enumerable.create(tmp.fromRoleName,tmp.toRoleName).select(new Func1<String,EdmAssociationEnd>(){
          public EdmAssociationEnd apply(          String input){
            if (ea.end1.role.equals(input))             return ea.end1;
            if (ea.end2.role.equals(input))             return ea.end2;
            throw new IllegalArgumentException("String_Node_Str" + input);
          }
        }
).toList();
        EdmNavigationProperty enp=new EdmNavigationProperty(tmp.name,ea,finalEnds.get(0),finalEnds.get(1));
        navProps.set(i,enp);
      }
      eet.setDeclaredNavigationProperties(navProps);
    }
    for (    EdmEntityContainer edmEntityContainer : edmSchema.entityContainers) {
      for (int i=0; i < edmEntityContainer.entitySets.size(); i++) {
        final TempEdmEntitySet tmpEes=(TempEdmEntitySet)edmEntityContainer.entitySets.get(i);
        EdmEntityType eet=allEetsByFQName.get(tmpEes.entityTypeName);
        if (eet == null)         throw new IllegalArgumentException("String_Node_Str" + tmpEes.entityTypeName);
        edmEntityContainer.entitySets.set(i,new EdmEntitySet(tmpEes.name,eet));
      }
    }
    for (    final EdmEntityContainer edmEntityContainer : edmSchema.entityContainers) {
      for (int i=0; i < edmEntityContainer.associationSets.size(); i++) {
        final TempEdmAssociationSet tmpEas=(TempEdmAssociationSet)edmEntityContainer.associationSets.get(i);
        final EdmAssociation ea=allEasByFQName.get(tmpEas.associationName);
        List<EdmAssociationSetEnd> finalEnds=Enumerable.create(tmpEas.end1,tmpEas.end2).select(new Func1<EdmAssociationSetEnd,EdmAssociationSetEnd>(){
          public EdmAssociationSetEnd apply(          EdmAssociationSetEnd input){
            final TempEdmAssociationSetEnd tmpEase=(TempEdmAssociationSetEnd)input;
            EdmAssociationEnd eae=ea.end1.role.equals(tmpEase.roleName) ? ea.end1 : ea.end2.role.equals(tmpEase.roleName) ? ea.end2 : null;
            if (eae == null)             throw new IllegalArgumentException("String_Node_Str" + tmpEase.roleName);
            EdmEntitySet ees=Enumerable.create(edmEntityContainer.entitySets).first(new Predicate1<EdmEntitySet>(){
              public boolean apply(              EdmEntitySet input){
                return input.name.equals(tmpEase.entitySetName);
              }
            }
);
            return new EdmAssociationSetEnd(eae,ees);
          }
        }
).toList();
        edmEntityContainer.associationSets.set(i,new EdmAssociationSet(tmpEas.name,ea,finalEnds.get(0),finalEnds.get(1)));
      }
    }
    for (    final EdmEntityContainer edmEntityContainer : edmSchema.entityContainers) {
      for (int i=0; i < edmEntityContainer.functionImports.size(); i++) {
        final TempEdmFunctionImport tmpEfi=(TempEdmFunctionImport)edmEntityContainer.functionImports.get(i);
        EdmEntitySet ees=Enumerable.create(edmEntityContainer.entitySets).firstOrNull(new Predicate1<EdmEntitySet>(){
          public boolean apply(          EdmEntitySet input){
            return input.name.equals(tmpEfi.entitySetName);
          }
        }
);
        EdmType type=null;
        type=EdmType.get(tmpEfi.returnTypeName);
        if (!type.isSimple()) {
          type=metadata.findEdmEntityType(tmpEfi.returnTypeName);
          if (type == null)           type=metadata.findEdmComplexType(tmpEfi.returnTypeName);
        }
        if (type == null)         throw new RuntimeException("String_Node_Str" + tmpEfi.returnTypeName);
        if (tmpEfi.isCollection) {
          type=new EdmCollectionType(tmpEfi.returnTypeName,type);
        }
        edmEntityContainer.functionImports.set(i,new EdmFunctionImport(tmpEfi.name,ees,type,tmpEfi.httpMethod,tmpEfi.parameters));
      }
    }
    for (    Entry<String,EdmEntityType> entry : allEetsByFQName.entrySet()) {
      String baseTypeName=entry.getValue().getFQBaseTypeName();
      if (null != baseTypeName) {
        EdmEntityType baseType=allEetsByFQName.get(baseTypeName);
        if (null == baseType) {
          throw new IllegalArgumentException("String_Node_Str" + baseTypeName);
        }
        entry.getValue().setBaseType(baseType);
      }
    }
  }
}

Fixed version (ground truth):
private static void resolve(EdmDataServices metadata){
  final Map<String,EdmEntityType> allEetsByFQName=Enumerable.create(metadata.getEntityTypes()).toMap(new Func1<EdmEntityType,String>(){
    public String apply(    EdmEntityType input){
      return input.getFQAliasName() != null ? input.getFQAliasName() : input.getFullyQualifiedTypeName();
    }
  }
);
  final Map<String,EdmAssociation> allEasByFQName=Enumerable.create(metadata.getAssociations()).toMap(new Func1<EdmAssociation,String>(){
    public String apply(    EdmAssociation input){
      return input.getFQAliasName() != null ? input.getFQAliasName() : input.getFQNamespaceName();
    }
  }
);
  for (  EdmSchema edmSchema : metadata.getSchemas()) {
    for (int i=0; i < edmSchema.associations.size(); i++) {
      EdmAssociation tmpAssociation=edmSchema.associations.get(i);
      List<EdmAssociationEnd> finalEnds=Enumerable.create(tmpAssociation.end1,tmpAssociation.end2).select(new Func1<EdmAssociationEnd,EdmAssociationEnd>(){
        public EdmAssociationEnd apply(        final EdmAssociationEnd tempEnd){
          EdmEntityType eet=allEetsByFQName.get(((TempEdmAssociationEnd)tempEnd).typeName);
          return new EdmAssociationEnd(tempEnd.role,eet,tempEnd.multiplicity);
        }
      }
).toList();
      EdmAssociation ea=new EdmAssociation(tmpAssociation.namespace,tmpAssociation.alias,tmpAssociation.name,finalEnds.get(0),finalEnds.get(1));
      edmSchema.associations.set(i,ea);
      allEasByFQName.put(ea.getFQAliasName() != null ? ea.getFQAliasName() : ea.getFQNamespaceName(),ea);
    }
    for (    EdmEntityType eet : edmSchema.entityTypes) {
      List<EdmNavigationProperty> navProps=eet.getDeclaredNavigationProperties().toList();
      for (int i=0; i < navProps.size(); i++) {
        final TempEdmNavigationProperty tmp=(TempEdmNavigationProperty)navProps.get(i);
        final EdmAssociation ea=allEasByFQName.get(tmp.relationshipName);
        List<EdmAssociationEnd> finalEnds=Enumerable.create(tmp.fromRoleName,tmp.toRoleName).select(new Func1<String,EdmAssociationEnd>(){
          public EdmAssociationEnd apply(          String input){
            if (ea.end1.role.equals(input))             return ea.end1;
            if (ea.end2.role.equals(input))             return ea.end2;
            throw new IllegalArgumentException("String_Node_Str" + input);
          }
        }
).toList();
        EdmNavigationProperty enp=new EdmNavigationProperty(tmp.name,ea,finalEnds.get(0),finalEnds.get(1));
        navProps.set(i,enp);
      }
      eet.setDeclaredNavigationProperties(Enumerable.create(navProps));
    }
    for (    EdmEntityContainer edmEntityContainer : edmSchema.entityContainers) {
      for (int i=0; i < edmEntityContainer.entitySets.size(); i++) {
        final TempEdmEntitySet tmpEes=(TempEdmEntitySet)edmEntityContainer.entitySets.get(i);
        EdmEntityType eet=allEetsByFQName.get(tmpEes.entityTypeName);
        if (eet == null)         throw new IllegalArgumentException("String_Node_Str" + tmpEes.entityTypeName);
        edmEntityContainer.entitySets.set(i,new EdmEntitySet(tmpEes.name,eet));
      }
    }
    for (    final EdmEntityContainer edmEntityContainer : edmSchema.entityContainers) {
      for (int i=0; i < edmEntityContainer.associationSets.size(); i++) {
        final TempEdmAssociationSet tmpEas=(TempEdmAssociationSet)edmEntityContainer.associationSets.get(i);
        final EdmAssociation ea=allEasByFQName.get(tmpEas.associationName);
        List<EdmAssociationSetEnd> finalEnds=Enumerable.create(tmpEas.end1,tmpEas.end2).select(new Func1<EdmAssociationSetEnd,EdmAssociationSetEnd>(){
          public EdmAssociationSetEnd apply(          EdmAssociationSetEnd input){
            final TempEdmAssociationSetEnd tmpEase=(TempEdmAssociationSetEnd)input;
            EdmAssociationEnd eae=ea.end1.role.equals(tmpEase.roleName) ? ea.end1 : ea.end2.role.equals(tmpEase.roleName) ? ea.end2 : null;
            if (eae == null)             throw new IllegalArgumentException("String_Node_Str" + tmpEase.roleName);
            EdmEntitySet ees=Enumerable.create(edmEntityContainer.entitySets).first(new Predicate1<EdmEntitySet>(){
              public boolean apply(              EdmEntitySet input){
                return input.name.equals(tmpEase.entitySetName);
              }
            }
);
            return new EdmAssociationSetEnd(eae,ees);
          }
        }
).toList();
        edmEntityContainer.associationSets.set(i,new EdmAssociationSet(tmpEas.name,ea,finalEnds.get(0),finalEnds.get(1)));
      }
    }
    for (    final EdmEntityContainer edmEntityContainer : edmSchema.entityContainers) {
      for (int i=0; i < edmEntityContainer.functionImports.size(); i++) {
        final TempEdmFunctionImport tmpEfi=(TempEdmFunctionImport)edmEntityContainer.functionImports.get(i);
        EdmEntitySet ees=Enumerable.create(edmEntityContainer.entitySets).firstOrNull(new Predicate1<EdmEntitySet>(){
          public boolean apply(          EdmEntitySet input){
            return input.name.equals(tmpEfi.entitySetName);
          }
        }
);
        EdmType type=null;
        type=EdmType.get(tmpEfi.returnTypeName);
        if (!type.isSimple()) {
          type=metadata.findEdmEntityType(tmpEfi.returnTypeName);
          if (type == null)           type=metadata.findEdmComplexType(tmpEfi.returnTypeName);
        }
        if (type == null)         throw new RuntimeException("String_Node_Str" + tmpEfi.returnTypeName);
        if (tmpEfi.isCollection) {
          type=new EdmCollectionType(tmpEfi.returnTypeName,type);
        }
        edmEntityContainer.functionImports.set(i,new EdmFunctionImport(tmpEfi.name,ees,type,tmpEfi.httpMethod,tmpEfi.parameters));
      }
    }
    for (    Entry<String,EdmEntityType> entry : allEetsByFQName.entrySet()) {
      String baseTypeName=entry.getValue().getFQBaseTypeName();
      if (null != baseTypeName) {
        EdmEntityType baseType=allEetsByFQName.get(baseTypeName);
        if (null == baseType) {
          throw new IllegalArgumentException("String_Node_Str" + baseTypeName);
        }
        entry.getValue().setBaseType(baseType);
      }
    }
  }
}