Program: 176023
Project: 176023
Buggy source:
private List iterateAndReturn(ResultSet rSet,Class entityClazz,EntityMetadata metadata){
  MetamodelImpl metaModel=(MetamodelImpl)kunderaMetadata.getApplicationMetadata().getMetamodel(metadata.getPersistenceUnit());
  EntityType entityType=metaModel.entity(metadata.getEntityClazz());
  Iterator<Row> rowIter=rSet.iterator();
  List results=new ArrayList();
  Map<String,Object> relationalValues=new HashMap<String,Object>();
  Map<String,Field> compositeColumns=new HashMap<String,Field>();
  Object compositeKeyInstance=null;
  if (metaModel.isEmbeddable(metadata.getIdAttribute().getBindableJavaType())) {
    compositeKeyInstance=getCompositeKeyInstance(metadata);
    EmbeddableType compositeKey=metaModel.embeddable(metadata.getIdAttribute().getBindableJavaType());
    Iterator<Attribute> attributes=compositeKey.getAttributes().iterator();
    while (attributes.hasNext()) {
      Attribute attribute=attributes.next();
      String columnName=((AbstractAttribute)attribute).getJPAColumnName();
      compositeColumns.put(columnName,(Field)attribute.getJavaMember());
    }
  }
  while (rowIter.hasNext()) {
    Object entity=null;
    Row row=rowIter.next();
    ColumnDefinitions columnDefs=row.getColumnDefinitions();
    Iterator<Definition> columnDefIter=columnDefs.iterator();
    entity=iteratorColumns(metadata,entityType,relationalValues,compositeColumns,compositeKeyInstance,entity,row,columnDefIter);
    if (compositeKeyInstance != null) {
      entity=CassandraUtilities.initialize(metadata,entity,compositeKeyInstance);
    }
    if (entity != null && entity.getClass().isAssignableFrom(metadata.getEntityClazz())) {
      Object rowKey=PropertyAccessorHelper.getId(entity,metadata);
      populateSecondaryTableData(rowKey,entity,metaModel,metadata);
      if (!relationalValues.isEmpty()) {
        results.add(new EnhanceEntity(entity,rowKey,relationalValues));
      }
 else {
        results.add(entity);
      }
    }
 else     if (entity != null) {
      results.add(entity);
    }
  }
  return results;
}

Fixed version (ground truth):
private List iterateAndReturn(ResultSet rSet,Class entityClazz,EntityMetadata metadata){
  MetamodelImpl metaModel=(MetamodelImpl)kunderaMetadata.getApplicationMetadata().getMetamodel(metadata.getPersistenceUnit());
  EntityType entityType=metaModel.entity(metadata.getEntityClazz());
  Iterator<Row> rowIter=rSet.iterator();
  List results=new ArrayList();
  Map<String,Object> relationalValues=new HashMap<String,Object>();
  Map<String,Field> compositeColumns=new HashMap<String,Field>();
  Object compositeKeyInstance=null;
  boolean isCompositeKey=false;
  if (metaModel.isEmbeddable(metadata.getIdAttribute().getBindableJavaType())) {
    isCompositeKey=true;
    EmbeddableType compositeKey=metaModel.embeddable(metadata.getIdAttribute().getBindableJavaType());
    Iterator<Attribute> attributes=compositeKey.getAttributes().iterator();
    while (attributes.hasNext()) {
      Attribute attribute=attributes.next();
      String columnName=((AbstractAttribute)attribute).getJPAColumnName();
      compositeColumns.put(columnName,(Field)attribute.getJavaMember());
    }
  }
  while (rowIter.hasNext()) {
    Object entity=null;
    Row row=rowIter.next();
    ColumnDefinitions columnDefs=row.getColumnDefinitions();
    Iterator<Definition> columnDefIter=columnDefs.iterator();
    if (isCompositeKey) {
      compositeKeyInstance=getCompositeKeyInstance(metadata);
    }
    entity=iteratorColumns(metadata,entityType,relationalValues,compositeColumns,compositeKeyInstance,entity,row,columnDefIter);
    if (compositeKeyInstance != null) {
      entity=CassandraUtilities.initialize(metadata,entity,compositeKeyInstance);
    }
    if (entity != null && entity.getClass().isAssignableFrom(metadata.getEntityClazz())) {
      Object rowKey=PropertyAccessorHelper.getId(entity,metadata);
      populateSecondaryTableData(rowKey,entity,metaModel,metadata);
      if (!relationalValues.isEmpty()) {
        results.add(new EnhanceEntity(entity,rowKey,relationalValues));
      }
 else {
        results.add(entity);
      }
    }
 else     if (entity != null) {
      results.add(entity);
    }
  }
  return results;
}