Program: 176593
Project: 176593
Buggy source:
/** 
 * Execute batch.
 * @return the int
 */
public int executeBatch(){
  String persistenceUnit=null;
  Cassandra.Client conn=null;
  Object pooledConnection=null;
  Map<Class<?>,Map<ByteBuffer,Map<String,List<Mutation>>>> batchMutationMap=new HashMap<Class<?>,Map<ByteBuffer,Map<String,List<Mutation>>>>();
  int recordsExecuted=0;
  String batchQuery=CQLTranslator.BATCH_QUERY;
  batchQuery=StringUtils.replace(batchQuery,CQLTranslator.STATEMENT,"String_Node_Str");
  StringBuilder batchQueryBuilder=new StringBuilder(batchQuery);
  try {
    for (    Node node : nodes) {
      if (node.isDirty()) {
        Object entity=node.getData();
        Object id=node.getEntityId();
        EntityMetadata metadata=KunderaMetadataManager.getEntityMetadata(node.getDataClass());
        persistenceUnit=metadata.getPersistenceUnit();
        isUpdate=node.isUpdate();
        MetamodelImpl metaModel=(MetamodelImpl)KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodel(metadata.getPersistenceUnit());
        if (isCQL3Enabled(metadata,metaModel)) {
          List<RelationHolder> relationHolders=getRelationHolders(node);
          String query;
          if (node.isInState(RemovedState.class)) {
            query=onDeleteQuery(metadata,metaModel,id);
          }
 else {
            query=createInsertQuery(metadata,entity,conn,relationHolders);
          }
          batchQueryBuilder.append(query);
        }
 else {
          if (node.isInState(RemovedState.class)) {
            delete(entity,id);
          }
 else {
            List<RelationHolder> relationHolders=getRelationHolders(node);
            Map<ByteBuffer,Map<String,List<Mutation>>> mutationMap=new HashMap<ByteBuffer,Map<String,List<Mutation>>>();
            mutationMap=prepareMutation(metadata,entity,id,relationHolders,mutationMap);
            recordsExecuted+=mutationMap.size();
            if (!batchMutationMap.containsKey(metadata.getEntityClazz())) {
              batchMutationMap.put(metadata.getEntityClazz(),mutationMap);
            }
 else {
              batchMutationMap.get(metadata.getEntityClazz()).putAll(mutationMap);
            }
            indexNode(node,metadata);
          }
        }
      }
    }
    if (!batchMutationMap.isEmpty()) {
      pooledConnection=getPooledConection(persistenceUnit);
      conn=getConnection(pooledConnection);
      for (      Class<?> entityClass : batchMutationMap.keySet()) {
        conn.batch_mutate(batchMutationMap.get(entityClass),consistencyLevel);
      }
    }
    if (!nodes.isEmpty() && isCQLEnabled) {
      batchQueryBuilder.append(CQLTranslator.APPLY_BATCH);
      executeCQLQuery(batchQueryBuilder.toString());
    }
  }
 catch (  InvalidRequestException e) {
    log.error("String_Node_Str" + e);
    throw new KunderaException(e);
  }
catch (  TException e) {
    log.error("String_Node_Str" + e);
    throw new KunderaException(e);
  }
catch (  UnavailableException e) {
    log.error("String_Node_Str" + e);
    throw new KunderaException(e);
  }
catch (  TimedOutException e) {
    log.error("String_Node_Str" + e);
    throw new KunderaException(e);
  }
catch (  SchemaDisagreementException e) {
    log.error("String_Node_Str" + e);
    throw new KunderaException(e);
  }
 finally {
    clear();
    releaseConnection(pooledConnection);
  }
  return recordsExecuted;
}

Fixed version (ground truth):
/** 
 * Execute batch.
 * @return the int
 */
public int executeBatch(){
  String persistenceUnit=null;
  Cassandra.Client conn=null;
  Object pooledConnection=null;
  Map<Class<?>,Map<ByteBuffer,Map<String,List<Mutation>>>> batchMutationMap=new HashMap<Class<?>,Map<ByteBuffer,Map<String,List<Mutation>>>>();
  int recordsExecuted=0;
  String batchQuery=CQLTranslator.BATCH_QUERY;
  batchQuery=StringUtils.replace(batchQuery,CQLTranslator.STATEMENT,"String_Node_Str");
  StringBuilder batchQueryBuilder=new StringBuilder(batchQuery);
  try {
    for (    Node node : nodes) {
      if (node.isDirty()) {
        node.handlePreEvent();
        Object entity=node.getData();
        Object id=node.getEntityId();
        EntityMetadata metadata=KunderaMetadataManager.getEntityMetadata(node.getDataClass());
        persistenceUnit=metadata.getPersistenceUnit();
        isUpdate=node.isUpdate();
        MetamodelImpl metaModel=(MetamodelImpl)KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodel(metadata.getPersistenceUnit());
        if (isCQL3Enabled(metadata,metaModel)) {
          List<RelationHolder> relationHolders=getRelationHolders(node);
          String query;
          if (node.isInState(RemovedState.class)) {
            query=onDeleteQuery(metadata,metaModel,id);
          }
 else {
            query=createInsertQuery(metadata,entity,conn,relationHolders);
          }
          batchQueryBuilder.append(query);
        }
 else {
          if (node.isInState(RemovedState.class)) {
            delete(entity,id);
          }
 else {
            List<RelationHolder> relationHolders=getRelationHolders(node);
            Map<ByteBuffer,Map<String,List<Mutation>>> mutationMap=new HashMap<ByteBuffer,Map<String,List<Mutation>>>();
            mutationMap=prepareMutation(metadata,entity,id,relationHolders,mutationMap);
            recordsExecuted+=mutationMap.size();
            if (!batchMutationMap.containsKey(metadata.getEntityClazz())) {
              batchMutationMap.put(metadata.getEntityClazz(),mutationMap);
            }
 else {
              batchMutationMap.get(metadata.getEntityClazz()).putAll(mutationMap);
            }
            indexNode(node,metadata);
          }
        }
        node.handlePostEvent();
      }
    }
    if (!batchMutationMap.isEmpty()) {
      pooledConnection=getPooledConection(persistenceUnit);
      conn=getConnection(pooledConnection);
      for (      Class<?> entityClass : batchMutationMap.keySet()) {
        conn.batch_mutate(batchMutationMap.get(entityClass),consistencyLevel);
      }
    }
    if (!nodes.isEmpty() && isCQLEnabled) {
      batchQueryBuilder.append(CQLTranslator.APPLY_BATCH);
      executeCQLQuery(batchQueryBuilder.toString());
    }
  }
 catch (  InvalidRequestException e) {
    log.error("String_Node_Str" + e);
    throw new KunderaException(e);
  }
catch (  TException e) {
    log.error("String_Node_Str" + e);
    throw new KunderaException(e);
  }
catch (  UnavailableException e) {
    log.error("String_Node_Str" + e);
    throw new KunderaException(e);
  }
catch (  TimedOutException e) {
    log.error("String_Node_Str" + e);
    throw new KunderaException(e);
  }
catch (  SchemaDisagreementException e) {
    log.error("String_Node_Str" + e);
    throw new KunderaException(e);
  }
 finally {
    clear();
    releaseConnection(pooledConnection);
  }
  return recordsExecuted;
}