Program: 176482
Project: 176482
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 {
    boolean isCql3Enabled=false;
    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)) {
          isCql3Enabled=true;
          List<RelationHolder> relationHolders=getRelationHolders(node);
          String query;
          if (node.isInState(RemovedState.class)) {
            query=onDeleteQuery(metadata,metaModel,id);
          }
 else {
            query=createInsertQuery(metadata,entity,conn,relationHolders,getTtlValues().get(metadata.getTableName()));
          }
          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=getConection(persistenceUnit);
      conn=getConnection(pooledConnection);
      for (      Class<?> entityClass : batchMutationMap.keySet()) {
        conn.batch_mutate(batchMutationMap.get(entityClass),consistencyLevel);
      }
    }
    if (!nodes.isEmpty() && isCql3Enabled) {
      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();
    if (pooledConnection != null) {
      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 {
    boolean isCql3Enabled=false;
    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)) {
          isCql3Enabled=true;
          List<RelationHolder> relationHolders=getRelationHolders(node);
          String query;
          if (node.isInState(RemovedState.class)) {
            query=onDeleteQuery(metadata,metaModel,id);
          }
 else {
            query=createInsertQuery(metadata,entity,conn,relationHolders,getTtlValues().get(metadata.getTableName()));
          }
          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=getConection(persistenceUnit);
      conn=getConnection(pooledConnection);
      for (      Class<?> entityClass : batchMutationMap.keySet()) {
        conn.batch_mutate(batchMutationMap.get(entityClass),consistencyLevel);
      }
    }
    if (!nodes.isEmpty() && isCql3Enabled) {
      batchQueryBuilder.append(CQLTranslator.APPLY_BATCH);
      executeCQLQuery(batchQueryBuilder.toString(),false);
    }
  }
 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();
    if (pooledConnection != null) {
      releaseConnection(pooledConnection);
    }
  }
  return recordsExecuted;
}