Program: 117428
Project: 117428
Buggy source:
@Override public OProperty virtualizeField(ODocument doc,String field){
  OProperty property=OPropertyPrototyper.newPrototype(doc.getClassName());
  property.setName(field);
  OType oType=doc.fieldType(field);
  property.setType(oType);
switch (oType) {
case LINK:
    ODocument link=doc.field(field);
  if (link != null)   property.setLinkedClass(link.getSchemaClass());
break;
case LINKBAG:
OCollection<OIdentifiable> bag=doc.field(field);
if (bag != null && bag.size() > 0) {
OIdentifiable linkIdentifiable=bag.iterator().next();
ORecord record=linkIdentifiable != null ? linkIdentifiable.getRecord() : null;
if (record != null && record instanceof ODocument) property.setLinkedClass(((ODocument)record).getSchemaClass());
}
break;
case LINKLIST:
case LINKSET:
Collection<ODocument> collection=doc.field(field);
if (collection != null && !collection.isEmpty()) {
link=collection.iterator().next();
if (link != null) property.setLinkedClass(link.getSchemaClass());
}
break;
case LINKMAP:
Map<String,ODocument> map=doc.field(field);
if (map != null && !map.isEmpty()) {
link=map.values().iterator().next();
if (link != null) property.setLinkedClass(link.getSchemaClass());
}
break;
case EMBEDDED:
Object value=doc.field(field);
OType linkedType=OType.getTypeByValue(value);
if (OType.EMBEDDED.equals(linkedType)) property.setLinkedClass(((ODocument)value).getSchemaClass());
 else property.setLinkedType(linkedType);
break;
case EMBEDDEDSET:
case EMBEDDEDLIST:
Collection<Object> objectCollection=doc.field(field);
if (objectCollection != null && !objectCollection.isEmpty()) {
value=objectCollection.iterator().next();
property.setLinkedType(OType.getTypeByValue(value));
}
break;
case EMBEDDEDMAP:
Map<String,Object> objectMap=doc.field(field);
if (objectMap != null && !objectMap.isEmpty()) {
value=objectMap.values().iterator().next();
property.setLinkedType(OType.getTypeByValue(value));
}
break;
default :
break;
}
return property;
}

Fixed version (ground truth):
@Override public OProperty virtualizeField(ODocument doc,String field){
  OProperty property=OPropertyPrototyper.newPrototype(doc.getClassName());
  property.setName(field);
  OType oType=doc.fieldType(field);
  if (oType == null)   oType=OType.ANY;
  property.setType(oType);
switch (oType) {
case LINK:
    ODocument link=doc.field(field);
  if (link != null)   property.setLinkedClass(link.getSchemaClass());
break;
case LINKBAG:
OCollection<OIdentifiable> bag=doc.field(field);
if (bag != null && bag.size() > 0) {
OIdentifiable linkIdentifiable=bag.iterator().next();
ORecord record=linkIdentifiable != null ? linkIdentifiable.getRecord() : null;
if (record != null && record instanceof ODocument) property.setLinkedClass(((ODocument)record).getSchemaClass());
}
break;
case LINKLIST:
case LINKSET:
Collection<ODocument> collection=doc.field(field);
if (collection != null && !collection.isEmpty()) {
link=collection.iterator().next();
if (link != null) property.setLinkedClass(link.getSchemaClass());
}
break;
case LINKMAP:
Map<String,ODocument> map=doc.field(field);
if (map != null && !map.isEmpty()) {
link=map.values().iterator().next();
if (link != null) property.setLinkedClass(link.getSchemaClass());
}
break;
case EMBEDDED:
Object value=doc.field(field);
OType linkedType=OType.getTypeByValue(value);
if (OType.EMBEDDED.equals(linkedType)) property.setLinkedClass(((ODocument)value).getSchemaClass());
 else property.setLinkedType(linkedType);
break;
case EMBEDDEDSET:
case EMBEDDEDLIST:
Collection<Object> objectCollection=doc.field(field);
if (objectCollection != null && !objectCollection.isEmpty()) {
value=objectCollection.iterator().next();
property.setLinkedType(OType.getTypeByValue(value));
}
break;
case EMBEDDEDMAP:
Map<String,Object> objectMap=doc.field(field);
if (objectMap != null && !objectMap.isEmpty()) {
value=objectMap.values().iterator().next();
property.setLinkedType(OType.getTypeByValue(value));
}
break;
default :
break;
}
return property;
}