Program: 176871
Project: 176871
Buggy source:
/** 
 * Populate entity from hbase data.
 * @param entity the entity
 * @param hbaseData the hbase data
 * @param m the m
 * @param rowKey the row key
 * @param relationNames the relation names
 * @return the object
 */
private Object populateEntityFromHbaseData(Object entity,HBaseData hbaseData,EntityMetadata m,String rowKey,List<String> relationNames){
  try {
    PropertyAccessorHelper.setId(entity,m,hbaseData.getRowKey());
    List<KeyValue> hbaseValues=hbaseData.getColumns();
    Map<String,Object> relations=new HashMap<String,Object>();
    List<Column> columns=m.getColumnsAsList();
    for (    Column column : columns) {
      Field columnField=column.getField();
      String columnName=column.getName();
      for (      KeyValue colData : hbaseValues) {
        String hbaseColumn=Bytes.toString(colData.getFamily());
        String colName=hbaseColumn;
        if (colName != null && colName.equalsIgnoreCase(columnName.toLowerCase())) {
          byte[] hbaseColumnValue=colData.getValue();
          PropertyAccessorHelper.set(entity,columnField,hbaseColumnValue);
        }
 else         if (relationNames != null && relationNames.contains(colName)) {
          relations.put(colName,Bytes.toString(colData.getValue()));
        }
      }
    }
    List<EmbeddedColumn> columnFamilies=m.getEmbeddedColumnsAsList();
    for (    EmbeddedColumn columnFamily : columnFamilies) {
      Field columnFamilyFieldInEntity=columnFamily.getField();
      Class<?> columnFamilyClass=columnFamilyFieldInEntity.getType();
      Map<String,Field> columnNameToFieldMap=MetadataUtils.createColumnsFieldMap(m,columnFamily);
      if (Collection.class.isAssignableFrom(columnFamilyClass)) {
        Field embeddedCollectionField=columnFamily.getField();
        Object[] embeddedObjectArr=new Object[hbaseValues.size()];
        Object embeddedObject=MetadataUtils.getEmbeddedGenericObjectInstance(embeddedCollectionField);
        int prevCFNameCounter=0;
        for (        KeyValue colData : hbaseValues) {
          String cfInHbase=Bytes.toString(colData.getFamily());
          if (!cfInHbase.startsWith(columnFamily.getName())) {
            if (relationNames != null && relationNames.contains(cfInHbase)) {
              relations.put(cfInHbase,Bytes.toString(colData.getValue()));
            }
            continue;
          }
          String cfNamePostfix=MetadataUtils.getEmbeddedCollectionPostfix(cfInHbase);
          int cfNameCounter=Integer.parseInt(cfNamePostfix);
          if (cfNameCounter != prevCFNameCounter) {
            prevCFNameCounter=cfNameCounter;
            embeddedObject=MetadataUtils.getEmbeddedGenericObjectInstance(embeddedCollectionField);
          }
          setHBaseDataIntoObject(colData,columnFamilyFieldInEntity,columnNameToFieldMap,embeddedObject);
          embeddedObjectArr[cfNameCounter]=embeddedObject;
          ElementCollectionCacheManager.getInstance().addElementCollectionCacheMapping(rowKey,embeddedObject,cfInHbase);
        }
        Collection embeddedCollection=MetadataUtils.getEmbeddedCollectionInstance(embeddedCollectionField);
        embeddedCollection.addAll(Arrays.asList(embeddedObjectArr));
        embeddedCollection.removeAll(Collections.singletonList(null));
        embeddedObjectArr=null;
        if (embeddedCollection != null && !embeddedCollection.isEmpty()) {
          PropertyAccessorHelper.set(entity,embeddedCollectionField,embeddedCollection);
        }
      }
 else {
        Object columnFamilyObj=columnFamilyClass.newInstance();
        for (        KeyValue colData : hbaseValues) {
          String cfInHbase=Bytes.toString(colData.getFamily());
          if (!cfInHbase.equals(columnFamily.getName())) {
            if (relationNames != null && relationNames.contains(cfInHbase)) {
              relations.put(cfInHbase,Bytes.toString(colData.getValue()));
            }
            continue;
          }
          String colName=Bytes.toString(colData.getQualifier());
          byte[] columnValue=colData.getValue();
          Field columnField=columnNameToFieldMap.get(colName);
          if (columnField != null) {
            if (columnFamilyFieldInEntity.isAnnotationPresent(Embedded.class) || columnFamilyFieldInEntity.isAnnotationPresent(ElementCollection.class)) {
              PropertyAccessorHelper.set(columnFamilyObj,columnField,columnValue);
            }
 else {
              columnFamilyObj=Bytes.toString(columnValue);
            }
          }
        }
        PropertyAccessorHelper.set(entity,columnFamilyFieldInEntity,columnFamilyObj);
      }
    }
    if (!relations.isEmpty()) {
      return new EnhanceEntity(entity,rowKey,relations);
    }
    return entity;
  }
 catch (  PropertyAccessException e1) {
    throw new RuntimeException(e1.getMessage());
  }
catch (  InstantiationException e1) {
    throw new RuntimeException(e1.getMessage());
  }
catch (  IllegalAccessException e1) {
    throw new RuntimeException(e1.getMessage());
  }
}

Fixed version (ground truth):
/** 
 * Populate entity from hbase data.
 * @param entity the entity
 * @param hbaseData the hbase data
 * @param m the m
 * @param rowKey the row key
 * @param relationNames the relation names
 * @return the object
 */
private Object populateEntityFromHbaseData(Object entity,HBaseData hbaseData,EntityMetadata m,String rowKey,List<String> relationNames){
  try {
    PropertyAccessorHelper.setId(entity,m,new String(hbaseData.getRowKey()));
    List<KeyValue> hbaseValues=hbaseData.getColumns();
    Map<String,Object> relations=new HashMap<String,Object>();
    List<Column> columns=m.getColumnsAsList();
    for (    Column column : columns) {
      Field columnField=column.getField();
      String columnName=column.getName();
      for (      KeyValue colData : hbaseValues) {
        String hbaseColumn=Bytes.toString(colData.getFamily());
        String colName=hbaseColumn;
        if (colName != null && colName.equalsIgnoreCase(columnName.toLowerCase())) {
          byte[] hbaseColumnValue=colData.getValue();
          PropertyAccessorHelper.set(entity,columnField,hbaseColumnValue);
        }
 else         if (relationNames != null && relationNames.contains(colName)) {
          relations.put(colName,Bytes.toString(colData.getValue()));
        }
      }
    }
    List<EmbeddedColumn> columnFamilies=m.getEmbeddedColumnsAsList();
    for (    EmbeddedColumn columnFamily : columnFamilies) {
      Field columnFamilyFieldInEntity=columnFamily.getField();
      Class<?> columnFamilyClass=columnFamilyFieldInEntity.getType();
      Map<String,Field> columnNameToFieldMap=MetadataUtils.createColumnsFieldMap(m,columnFamily);
      if (Collection.class.isAssignableFrom(columnFamilyClass)) {
        Field embeddedCollectionField=columnFamily.getField();
        Object[] embeddedObjectArr=new Object[hbaseValues.size()];
        Object embeddedObject=MetadataUtils.getEmbeddedGenericObjectInstance(embeddedCollectionField);
        int prevCFNameCounter=0;
        for (        KeyValue colData : hbaseValues) {
          String cfInHbase=Bytes.toString(colData.getFamily());
          if (!cfInHbase.startsWith(columnFamily.getName())) {
            if (relationNames != null && relationNames.contains(cfInHbase)) {
              relations.put(cfInHbase,Bytes.toString(colData.getValue()));
            }
            continue;
          }
          String cfNamePostfix=MetadataUtils.getEmbeddedCollectionPostfix(cfInHbase);
          int cfNameCounter=Integer.parseInt(cfNamePostfix);
          if (cfNameCounter != prevCFNameCounter) {
            prevCFNameCounter=cfNameCounter;
            embeddedObject=MetadataUtils.getEmbeddedGenericObjectInstance(embeddedCollectionField);
          }
          setHBaseDataIntoObject(colData,columnFamilyFieldInEntity,columnNameToFieldMap,embeddedObject);
          embeddedObjectArr[cfNameCounter]=embeddedObject;
          ElementCollectionCacheManager.getInstance().addElementCollectionCacheMapping(rowKey,embeddedObject,cfInHbase);
        }
        Collection embeddedCollection=MetadataUtils.getEmbeddedCollectionInstance(embeddedCollectionField);
        embeddedCollection.addAll(Arrays.asList(embeddedObjectArr));
        embeddedCollection.removeAll(Collections.singletonList(null));
        embeddedObjectArr=null;
        if (embeddedCollection != null && !embeddedCollection.isEmpty()) {
          PropertyAccessorHelper.set(entity,embeddedCollectionField,embeddedCollection);
        }
      }
 else {
        Object columnFamilyObj=columnFamilyClass.newInstance();
        for (        KeyValue colData : hbaseValues) {
          String cfInHbase=Bytes.toString(colData.getFamily());
          if (!cfInHbase.equals(columnFamily.getName())) {
            if (relationNames != null && relationNames.contains(cfInHbase)) {
              relations.put(cfInHbase,Bytes.toString(colData.getValue()));
            }
            continue;
          }
          String colName=Bytes.toString(colData.getQualifier());
          byte[] columnValue=colData.getValue();
          Field columnField=columnNameToFieldMap.get(colName);
          if (columnField != null) {
            if (columnFamilyFieldInEntity.isAnnotationPresent(Embedded.class) || columnFamilyFieldInEntity.isAnnotationPresent(ElementCollection.class)) {
              PropertyAccessorHelper.set(columnFamilyObj,columnField,columnValue);
            }
 else {
              columnFamilyObj=Bytes.toString(columnValue);
            }
          }
        }
        PropertyAccessorHelper.set(entity,columnFamilyFieldInEntity,columnFamilyObj);
      }
    }
    if (!relations.isEmpty()) {
      return new EnhanceEntity(entity,rowKey,relations);
    }
    return entity;
  }
 catch (  PropertyAccessException e1) {
    throw new RuntimeException(e1.getMessage());
  }
catch (  InstantiationException e1) {
    throw new RuntimeException(e1.getMessage());
  }
catch (  IllegalAccessException e1) {
    throw new RuntimeException(e1.getMessage());
  }
}