Program: 60291
Project: 60291
Buggy source:
private Object encodeMap(){
  ParameterizedType paramType=(ParameterizedType)field.getGenericType();
  Type[] types=paramType.getActualTypeArguments();
  boolean isArray=false;
  boolean isCollection=false;
  boolean isSingle=false;
  Class elementType=null;
  if (types[1] instanceof GenericArrayType) {
    isArray=true;
    GenericArrayType g=(GenericArrayType)types[1];
    elementType=(Class)g.getGenericComponentType();
  }
 else   if (types[1] instanceof ParameterizedType) {
    isCollection=true;
    ParameterizedType p=(ParameterizedType)types[1];
    elementType=(Class)p.getActualTypeArguments()[0];
  }
 else {
    Class<?> actualType=FieldUtil.getClassOfType(types[1]);
    if (actualType.isArray()) {
      isArray=true;
      elementType=actualType.getComponentType();
    }
 else {
      isSingle=true;
    }
  }
  Map result=new HashMap();
  InternalDao dao=null;
  if (isSingle) {
    Class<?> cls=FieldUtil.getRealType((Class)types[1],field);
    dao=DaoCache.getInstance().get(cls);
  }
  Map map=(Map)value;
  for (  Object key : map.keySet()) {
    Object entryValue=map.get(key);
    if (isSingle) {
      BuguEntity entity=(BuguEntity)entryValue;
      if (entity != null) {
        if (cascadeCU) {
          dao.save(entity);
        }
        result.put(key,ReferenceUtil.toDbReference(refList,entity.getClass(),entity.getId()));
      }
 else {
        result.put(key,null);
      }
    }
 else     if (isArray) {
      Object arr=encodeArray(elementType,entryValue);
      result.put(key,arr);
    }
 else     if (isCollection) {
      Object arr=encodeCollection(elementType,entryValue);
      result.put(key,arr);
    }
  }
  return result;
}

Fixed version (ground truth):
private Object encodeMap(){
  ParameterizedType paramType=(ParameterizedType)field.getGenericType();
  Type[] types=paramType.getActualTypeArguments();
  boolean isArray=false;
  boolean isCollection=false;
  boolean isSingle=false;
  Class elementType=null;
  if (types[1] instanceof GenericArrayType) {
    isArray=true;
    GenericArrayType g=(GenericArrayType)types[1];
    elementType=(Class)g.getGenericComponentType();
  }
 else   if (types[1] instanceof ParameterizedType) {
    isCollection=true;
    ParameterizedType p=(ParameterizedType)types[1];
    elementType=(Class)p.getActualTypeArguments()[0];
  }
 else {
    Class<?> actualType=FieldUtil.getClassOfType(types[1]);
    if (actualType.isArray()) {
      isArray=true;
      elementType=actualType.getComponentType();
    }
 else {
      isSingle=true;
    }
  }
  Map result=new HashMap();
  InternalDao dao=null;
  if (isSingle) {
    Class<?> cls=FieldUtil.getRealType((Class)types[1],field);
    dao=DaoCache.getInstance().get(cls);
  }
  Map map=(Map)value;
  for (  Object key : map.keySet()) {
    Object entryValue=map.get(key);
    if (isSingle) {
      BuguEntity entity=(BuguEntity)entryValue;
      if (entity != null) {
        if (!withoutCascade && cascadeCU) {
          dao.saveWithoutCascade(entity,true);
        }
        result.put(key,ReferenceUtil.toDbReference(refList,entity.getClass(),entity.getId()));
      }
 else {
        result.put(key,null);
      }
    }
 else     if (isArray) {
      Object arr=encodeArray(elementType,entryValue);
      result.put(key,arr);
    }
 else     if (isCollection) {
      Object arr=encodeCollection(elementType,entryValue);
      result.put(key,arr);
    }
  }
  return result;
}