Program: 59612
Project: 59612
Buggy source:
protected OEntity toOEntity(EdmEntitySet ees,Object obj,List<EntitySimpleProperty> expand){
  EntityInfo<?,?> ei=eis.get(ees.name);
  final List<OLink> links=new ArrayList<OLink>();
  final List<OProperty<?>> properties=new ArrayList<OProperty<?>>();
  Object keyValue=ei.id.apply(obj);
  properties.add(OProperties.simple(ID_PROPNAME,getEdmType(ei.keyClass),keyValue));
  for (  String propName : ei.properties.getPropertyNames()) {
    EdmSimpleType type;
    Object value=ei.properties.getPropertyValue(obj,propName);
    Class<?> propType=ei.properties.getPropertyType(propName);
    type=findEdmType(propType);
    if (type == null)     continue;
    properties.add(OProperties.simple(propName,type,value));
  }
  if (expand != null && !expand.isEmpty()) {
    EdmEntityType edmEntityType=ees.type;
    for (    final EntitySimpleProperty propPath : expand) {
      String[] props=propPath.getPropertyName().split("String_Node_Str",2);
      String prop=props[0];
      List<EntitySimpleProperty> remainingPropPath=props.length > 1 ? Arrays.asList(org.odata4j.expression.Expression.simpleProperty(props[1])) : null;
      EdmNavigationProperty edmNavProperty=edmEntityType.findNavigationProperty(prop);
      if (edmNavProperty == null)       continue;
      if (edmNavProperty.toRole.multiplicity == EdmMultiplicity.MANY) {
        List<OEntity> relatedEntities=new ArrayList<OEntity>();
        Iterable<?> values=ei.properties.getCollectionValue(obj,prop);
        if (values != null) {
          EdmEntitySet relEntitySet=null;
          for (          final Object entity : values) {
            if (relEntitySet == null) {
              EntityInfo<?,?> oei=Enumerable.create(eis.values()).firstOrNull(new Predicate1<InMemoryProducer.EntityInfo<?,?>>(){
                @Override public boolean apply(                EntityInfo<?,?> input){
                  return entity.getClass().equals(input.entityClass);
                }
              }
);
              relEntitySet=getMetadata().getEdmEntitySet(oei.entitySetName);
            }
            relatedEntities.add(toOEntity(relEntitySet,entity,remainingPropPath));
          }
        }
        links.add(OLinks.relatedEntitiesInline(null,edmNavProperty.name,null,relatedEntities));
      }
 else {
        final Object entity=ei.properties.getPropertyValue(obj,prop);
        OEntity relatedEntity=null;
        if (entity != null) {
          EntityInfo<?,?> oei=Enumerable.create(eis.values()).firstOrNull(new Predicate1<InMemoryProducer.EntityInfo<?,?>>(){
            @Override public boolean apply(            EntityInfo<?,?> input){
              return entity.getClass().equals(input.entityClass);
            }
          }
);
          EdmEntitySet relEntitySet=getMetadata().getEdmEntitySet(oei.entitySetName);
          relatedEntity=toOEntity(relEntitySet,entity,remainingPropPath);
        }
        links.add(OLinks.relatedEntityInline(null,edmNavProperty.name,null,relatedEntity));
      }
    }
  }
  for (  final EdmNavigationProperty ep : ees.type.getNavigationProperties()) {
    boolean expanded=null != Enumerable.create(links).firstOrNull(new Predicate1<OLink>(){
      @Override public boolean apply(      OLink t){
        return t.getTitle().equals(ep.name);
      }
    }
);
    if (!expanded) {
      if (ep.toRole.multiplicity == EdmMultiplicity.MANY) {
        links.add(OLinks.relatedEntities(null,ep.name,null));
      }
 else {
        links.add(OLinks.relatedEntity(null,ep.name,null));
      }
    }
  }
  return OEntities.create(ees,OEntityKey.create(keyValue),properties,links);
}

Fixed version (ground truth):
protected OEntity toOEntity(EdmEntitySet ees,Object obj,List<EntitySimpleProperty> expand){
  EntityInfo<?,?> ei=eis.get(ees.name);
  final List<OLink> links=new ArrayList<OLink>();
  final List<OProperty<?>> properties=new ArrayList<OProperty<?>>();
  Object keyValue=ei.properties.getPropertyValue(obj,ID_PROPNAME);
  for (  String propName : ei.properties.getPropertyNames()) {
    EdmSimpleType type;
    Object value=ei.properties.getPropertyValue(obj,propName);
    Class<?> propType=ei.properties.getPropertyType(propName);
    type=findEdmType(propType);
    if (type == null)     continue;
    properties.add(OProperties.simple(propName,type,value));
  }
  if (expand != null && !expand.isEmpty()) {
    EdmEntityType edmEntityType=ees.type;
    for (    final EntitySimpleProperty propPath : expand) {
      String[] props=propPath.getPropertyName().split("String_Node_Str",2);
      String prop=props[0];
      List<EntitySimpleProperty> remainingPropPath=props.length > 1 ? Arrays.asList(org.odata4j.expression.Expression.simpleProperty(props[1])) : null;
      EdmNavigationProperty edmNavProperty=edmEntityType.findNavigationProperty(prop);
      if (edmNavProperty == null)       continue;
      if (edmNavProperty.toRole.multiplicity == EdmMultiplicity.MANY) {
        List<OEntity> relatedEntities=new ArrayList<OEntity>();
        Iterable<?> values=ei.properties.getCollectionValue(obj,prop);
        if (values != null) {
          EdmEntitySet relEntitySet=null;
          for (          final Object entity : values) {
            if (relEntitySet == null) {
              EntityInfo<?,?> oei=Enumerable.create(eis.values()).firstOrNull(new Predicate1<InMemoryProducer.EntityInfo<?,?>>(){
                @Override public boolean apply(                EntityInfo<?,?> input){
                  return entity.getClass().equals(input.entityClass);
                }
              }
);
              relEntitySet=getMetadata().getEdmEntitySet(oei.entitySetName);
            }
            relatedEntities.add(toOEntity(relEntitySet,entity,remainingPropPath));
          }
        }
        links.add(OLinks.relatedEntitiesInline(null,edmNavProperty.name,null,relatedEntities));
      }
 else {
        final Object entity=ei.properties.getPropertyValue(obj,prop);
        OEntity relatedEntity=null;
        if (entity != null) {
          EntityInfo<?,?> oei=Enumerable.create(eis.values()).firstOrNull(new Predicate1<InMemoryProducer.EntityInfo<?,?>>(){
            @Override public boolean apply(            EntityInfo<?,?> input){
              return entity.getClass().equals(input.entityClass);
            }
          }
);
          EdmEntitySet relEntitySet=getMetadata().getEdmEntitySet(oei.entitySetName);
          relatedEntity=toOEntity(relEntitySet,entity,remainingPropPath);
        }
        links.add(OLinks.relatedEntityInline(null,edmNavProperty.name,null,relatedEntity));
      }
    }
  }
  for (  final EdmNavigationProperty ep : ees.type.getNavigationProperties()) {
    boolean expanded=null != Enumerable.create(links).firstOrNull(new Predicate1<OLink>(){
      @Override public boolean apply(      OLink t){
        return t.getTitle().equals(ep.name);
      }
    }
);
    if (!expanded) {
      if (ep.toRole.multiplicity == EdmMultiplicity.MANY) {
        links.add(OLinks.relatedEntities(null,ep.name,null));
      }
 else {
        links.add(OLinks.relatedEntity(null,ep.name,null));
      }
    }
  }
  return OEntities.create(ees,OEntityKey.create(keyValue),properties,links);
}