Program: 176376
Project: 176376
Buggy source:
/** 
 * Populate entity.
 * @param tr the tr
 * @param m the m
 * @param relationNames the relation names
 * @param isWrapReq the is wrap req
 * @return the object
 */
public Object populateEntity(ThriftRow tr,EntityMetadata m,List<String> relationNames,boolean isWrapReq){
  Map<String,Object> relations=new HashMap<String,Object>();
  Object entity=null;
  try {
    MetamodelImpl metaModel=(MetamodelImpl)KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodel(m.getPersistenceUnit());
    EntityType entityType=metaModel.entity(m.getEntityClazz());
    boolean isCql3Enabled=clientBase.isCql3Enabled(m);
    for (    Column column : tr.getColumns()) {
      if (column != null) {
        String thriftColumnName=PropertyAccessorFactory.STRING.fromBytes(String.class,column.getName());
        if (CassandraConstants.CQL_KEY.equalsIgnoreCase(thriftColumnName) && tr.getId() == null) {
          entity=initialize(m,entity,null);
          setId(m,entity,column.getValue(),isCql3Enabled);
        }
 else {
          entity=onColumn(column,m,entity,entityType,relationNames,isWrapReq,relations,isCql3Enabled);
        }
      }
    }
    Collection embeddedCollection=null;
    Field embeddedCollectionField=null;
    boolean mappingProcessed=false;
    Map<String,Field> columnNameToFieldMap=new HashMap<String,Field>();
    Map<String,Field> superColumnNameToFieldMap=new HashMap<String,Field>();
    for (    SuperColumn superColumn : tr.getSuperColumns()) {
      if (superColumn != null) {
        entity=initialize(m,entity,tr.getId());
        String scName=PropertyAccessorFactory.STRING.fromBytes(String.class,superColumn.getName());
        String scNamePrefix=null;
        Map<String,Set<String>> foreignKeysMap=new HashMap<String,Set<String>>();
        if (!mappingProcessed) {
          MetadataUtils.populateColumnAndSuperColumnMaps(m,columnNameToFieldMap,superColumnNameToFieldMap);
          mappingProcessed=true;
        }
        if (scName.indexOf(Constants.EMBEDDED_COLUMN_NAME_DELIMITER) != -1) {
          scNamePrefix=MetadataUtils.getEmbeddedCollectionPrefix(scName);
          embeddedCollectionField=superColumnNameToFieldMap.get(scNamePrefix);
          if (embeddedCollection == null) {
            embeddedCollection=MetadataUtils.getEmbeddedCollectionInstance(embeddedCollectionField);
          }
          Object embeddedObject=MetadataUtils.getEmbeddedGenericObjectInstance(embeddedCollectionField);
          scrollOverSuperColumn(m,relationNames,isWrapReq,relations,entityType,superColumn,embeddedObject,columnNameToFieldMap);
          Collection collection=PropertyAccessorHelper.getCollectionInstance(embeddedCollectionField);
          collection.add(embeddedObject);
          PropertyAccessorHelper.set(entity,embeddedCollectionField,collection);
          embeddedCollection.add(embeddedObject);
          ElementCollectionCacheManager.getInstance().addElementCollectionCacheMapping(tr.getId(),embeddedObject,scName);
        }
 else {
          if (superColumnNameToFieldMap.containsKey(scName)) {
            Field field=superColumnNameToFieldMap.get(scName);
            Object embeddedObj=field.getType().newInstance();
            scrollOverSuperColumn(m,relationNames,isWrapReq,relations,entityType,superColumn,embeddedObj,columnNameToFieldMap);
            PropertyAccessorHelper.set(entity,field,embeddedObj);
          }
 else {
            scrollOverSuperColumn(m,relationNames,isWrapReq,relations,entityType,superColumn,entity,isCql3Enabled);
          }
        }
      }
    }
    mappingProcessed=false;
    for (    CounterColumn counterColumn : tr.getCounterColumns()) {
      if (counterColumn != null) {
        entity=initialize(m,entity,tr.getId());
        onCounterColumn(counterColumn,m,entity,entityType,relationNames,isWrapReq,relations,isCql3Enabled);
      }
    }
    for (    CounterSuperColumn counterSuperColumn : tr.getCounterSuperColumns()) {
      if (counterSuperColumn != null) {
        entity=initialize(m,entity,tr.getId());
        String scName=PropertyAccessorFactory.STRING.fromBytes(String.class,counterSuperColumn.getName());
        String scNamePrefix=null;
        Map<String,Set<String>> foreignKeysMap=new HashMap<String,Set<String>>();
        if (!mappingProcessed) {
          MetadataUtils.populateColumnAndSuperColumnMaps(m,columnNameToFieldMap,superColumnNameToFieldMap);
          mappingProcessed=true;
        }
        if (scName.indexOf(Constants.EMBEDDED_COLUMN_NAME_DELIMITER) != -1) {
          scNamePrefix=MetadataUtils.getEmbeddedCollectionPrefix(scName);
          embeddedCollectionField=superColumnNameToFieldMap.get(scNamePrefix);
          if (embeddedCollection == null) {
            embeddedCollection=MetadataUtils.getEmbeddedCollectionInstance(embeddedCollectionField);
          }
          Object embeddedObject=MetadataUtils.getEmbeddedGenericObjectInstance(embeddedCollectionField);
          scrollOverCounterSuperColumn(m,relationNames,isWrapReq,relations,entityType,counterSuperColumn,embeddedObject,columnNameToFieldMap);
          embeddedCollection.add(embeddedObject);
          ElementCollectionCacheManager.getInstance().addElementCollectionCacheMapping(tr.getId(),embeddedObject,scName);
        }
 else {
          if (superColumnNameToFieldMap.containsKey(scName)) {
            Field field=superColumnNameToFieldMap.get(scName);
            Object embeddedObj=field.getType().newInstance();
            scrollOverCounterSuperColumn(m,relationNames,isWrapReq,relations,entityType,counterSuperColumn,embeddedObj,columnNameToFieldMap);
            PropertyAccessorHelper.set(entity,field,embeddedObj);
          }
 else {
            scrollOverCounterSuperColumn(m,relationNames,isWrapReq,relations,entityType,counterSuperColumn,entity,isCql3Enabled);
          }
        }
      }
    }
    if (embeddedCollection != null && !embeddedCollection.isEmpty()) {
      PropertyAccessorHelper.set(entity,embeddedCollectionField,embeddedCollection);
    }
  }
 catch (  InstantiationException iex) {
    log.error("String_Node_Str",iex);
    throw new PersistenceException(iex);
  }
catch (  IllegalAccessException iaex) {
    log.error("String_Node_Str",iaex);
    throw new PersistenceException(iaex);
  }
  if (entity != null && tr.getId() != null) {
    PropertyAccessorHelper.setId(entity,m,tr.getId());
  }
  return isWrapReq && relations != null && !relations.isEmpty() ? new EnhanceEntity(entity,PropertyAccessorHelper.getId(entity,m),relations) : entity;
}

Fixed version (ground truth):
/** 
 * Populate entity.
 * @param tr the tr
 * @param m the m
 * @param relationNames the relation names
 * @param isWrapReq the is wrap req
 * @return the object
 */
public Object populateEntity(ThriftRow tr,EntityMetadata m,List<String> relationNames,boolean isWrapReq){
  Map<String,Object> relations=new HashMap<String,Object>();
  Object entity=null;
  try {
    MetamodelImpl metaModel=(MetamodelImpl)KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodel(m.getPersistenceUnit());
    EntityType entityType=metaModel.entity(m.getEntityClazz());
    boolean isCql3Enabled=clientBase.isCql3Enabled(m);
    for (    Column column : tr.getColumns()) {
      if (column != null) {
        String thriftColumnName=PropertyAccessorFactory.STRING.fromBytes(String.class,column.getName());
        if (CassandraConstants.CQL_KEY.equalsIgnoreCase(thriftColumnName) && tr.getId() == null) {
          entity=initialize(m,entity,null);
          setId(m,entity,column.getValue(),isCql3Enabled);
        }
 else {
          entity=onColumn(column,m,entity,entityType,relationNames,isWrapReq,relations,isCql3Enabled);
        }
      }
    }
    Collection embeddedCollection=null;
    Field embeddedCollectionField=null;
    boolean mappingProcessed=false;
    Map<String,Field> columnNameToFieldMap=new HashMap<String,Field>();
    Map<String,Field> superColumnNameToFieldMap=new HashMap<String,Field>();
    for (    SuperColumn superColumn : tr.getSuperColumns()) {
      if (superColumn != null) {
        entity=initialize(m,entity,tr.getId());
        String scName=PropertyAccessorFactory.STRING.fromBytes(String.class,superColumn.getName());
        String scNamePrefix=null;
        Map<String,Set<String>> foreignKeysMap=new HashMap<String,Set<String>>();
        if (!mappingProcessed) {
          MetadataUtils.populateColumnAndSuperColumnMaps(m,columnNameToFieldMap,superColumnNameToFieldMap);
          mappingProcessed=true;
        }
        if (scName.indexOf(Constants.EMBEDDED_COLUMN_NAME_DELIMITER) != -1) {
          scNamePrefix=MetadataUtils.getEmbeddedCollectionPrefix(scName);
          embeddedCollectionField=superColumnNameToFieldMap.get(scNamePrefix);
          if (embeddedCollection == null) {
            embeddedCollection=MetadataUtils.getEmbeddedCollectionInstance(embeddedCollectionField);
          }
          Object embeddedObject=MetadataUtils.getEmbeddedGenericObjectInstance(embeddedCollectionField);
          scrollOverSuperColumn(m,relationNames,isWrapReq,relations,entityType,superColumn,embeddedObject,columnNameToFieldMap);
          Collection collection=PropertyAccessorHelper.getCollectionInstance(embeddedCollectionField);
          collection.add(embeddedObject);
          PropertyAccessorHelper.set(entity,embeddedCollectionField,collection);
          embeddedCollection.add(embeddedObject);
          ElementCollectionCacheManager.getInstance().addElementCollectionCacheMapping(tr.getId(),embeddedObject,scName);
        }
 else {
          if (superColumnNameToFieldMap.containsKey(scName)) {
            Field field=superColumnNameToFieldMap.get(scName);
            Object embeddedObj=field.getType().newInstance();
            scrollOverSuperColumn(m,relationNames,isWrapReq,relations,entityType,superColumn,embeddedObj,columnNameToFieldMap);
            PropertyAccessorHelper.set(entity,field,embeddedObj);
          }
 else {
            scrollOverSuperColumn(m,relationNames,isWrapReq,relations,entityType,superColumn,entity,isCql3Enabled);
          }
        }
      }
    }
    mappingProcessed=false;
    for (    CounterColumn counterColumn : tr.getCounterColumns()) {
      if (counterColumn != null) {
        entity=initialize(m,entity,tr.getId());
        onCounterColumn(counterColumn,m,entity,entityType,relationNames,isWrapReq,relations,isCql3Enabled);
      }
    }
    for (    CounterSuperColumn counterSuperColumn : tr.getCounterSuperColumns()) {
      if (counterSuperColumn != null) {
        entity=initialize(m,entity,tr.getId());
        String scName=PropertyAccessorFactory.STRING.fromBytes(String.class,counterSuperColumn.getName());
        String scNamePrefix=null;
        Map<String,Set<String>> foreignKeysMap=new HashMap<String,Set<String>>();
        if (!mappingProcessed) {
          MetadataUtils.populateColumnAndSuperColumnMaps(m,columnNameToFieldMap,superColumnNameToFieldMap);
          mappingProcessed=true;
        }
        if (scName.indexOf(Constants.EMBEDDED_COLUMN_NAME_DELIMITER) != -1) {
          scNamePrefix=MetadataUtils.getEmbeddedCollectionPrefix(scName);
          embeddedCollectionField=superColumnNameToFieldMap.get(scNamePrefix);
          if (embeddedCollection == null) {
            embeddedCollection=MetadataUtils.getEmbeddedCollectionInstance(embeddedCollectionField);
          }
          Object embeddedObject=MetadataUtils.getEmbeddedGenericObjectInstance(embeddedCollectionField);
          scrollOverCounterSuperColumn(m,relationNames,isWrapReq,relations,entityType,counterSuperColumn,embeddedObject,columnNameToFieldMap);
          embeddedCollection.add(embeddedObject);
          ElementCollectionCacheManager.getInstance().addElementCollectionCacheMapping(tr.getId(),embeddedObject,scName);
        }
 else {
          if (superColumnNameToFieldMap.containsKey(scName)) {
            Field field=superColumnNameToFieldMap.get(scName);
            Object embeddedObj=field.getType().newInstance();
            scrollOverCounterSuperColumn(m,relationNames,isWrapReq,relations,entityType,counterSuperColumn,embeddedObj,columnNameToFieldMap);
            PropertyAccessorHelper.set(entity,field,embeddedObj);
          }
 else {
            scrollOverCounterSuperColumn(m,relationNames,isWrapReq,relations,entityType,counterSuperColumn,entity,isCql3Enabled);
          }
        }
      }
    }
    if (embeddedCollection != null && !embeddedCollection.isEmpty()) {
      PropertyAccessorHelper.set(entity,embeddedCollectionField,embeddedCollection);
    }
  }
 catch (  Exception e) {
    log.error("String_Node_Str",e);
    throw new PersistenceException(e);
  }
  if (entity != null && tr.getId() != null) {
    PropertyAccessorHelper.setId(entity,m,tr.getId());
  }
  return isWrapReq && relations != null && !relations.isEmpty() ? new EnhanceEntity(entity,PropertyAccessorHelper.getId(entity,m),relations) : entity;
}