Program: 47754
Project: 47754
Buggy source:
/** 
 * Updates the schema information for a given column family with any fields in the supplied RowMeta that aren't defined in the schema. Abuses the schema "comment" field to store information on any indexed values that might be in the fields in the RowMeta.
 * @param conn the connection to use
 * @param colFamilyName the name of the column family to update
 * @param inputMeta the row meta containing (potentially) new fields
 * @param keyIndex the index of the key field in the row meta
 * @param cassandraMeta meta data for the cassandra column family
 * @throws Exception if a problem occurs updating the schema
 */
public static void updateCassandraMeta(CassandraConnection conn,String colFamilyName,RowMetaInterface inputMeta,int keyIndex,CassandraColumnMetaData cassandraMeta) throws Exception {
  KsDef keySpace=conn.describeKeyspace();
  List<CfDef> colFams=null;
  if (keySpace != null) {
    colFams=keySpace.getCf_defs();
  }
 else {
    throw new Exception("String_Node_Str");
  }
  CfDef colFamDefToUpdate=null;
  for (  CfDef fam : colFams) {
    String columnFamilyName=fam.getName();
    if (columnFamilyName.equals(colFamilyName)) {
      colFamDefToUpdate=fam;
      break;
    }
  }
  if (colFamDefToUpdate == null) {
    throw new Exception("String_Node_Str" + "String_Node_Str" + colFamilyName + "String_Node_Str");
  }
  String comment=colFamDefToUpdate.getComment();
  List<ValueMetaInterface> indexedVals=new ArrayList<ValueMetaInterface>();
  for (int i=0; i < inputMeta.size(); i++) {
    if (i != keyIndex) {
      ValueMetaInterface colMeta=inputMeta.getValueMeta(i);
      if (colMeta.getStorageType() == ValueMetaInterface.STORAGE_TYPE_INDEXED) {
        indexedVals.add(colMeta);
      }
      String colName=colMeta.getName();
      if (!cassandraMeta.columnExistsInSchema(colName)) {
        String colType=CassandraColumnMetaData.getCassandraTypeForValueMeta(colMeta);
        ColumnDef newCol=new ColumnDef(ByteBuffer.wrap(colName.getBytes()),colType);
        colFamDefToUpdate.addToColumn_metadata(newCol);
      }
    }
  }
  if (indexedVals.size() > 0) {
    String before="String_Node_Str";
    String after="String_Node_Str";
    String meta="String_Node_Str";
    if (comment != null && comment.length() > 0) {
      if (comment.indexOf("String_Node_Str") >= 0) {
        before=comment.substring(0,comment.indexOf("String_Node_Str"));
        after=comment.substring(comment.lastIndexOf("String_Node_Str") + 3,comment.length());
        meta=comment.substring(comment.indexOf("String_Node_Str",comment.lastIndexOf("String_Node_Str")));
        meta.replace("String_Node_Str","String_Node_Str");
      }
    }
    StringBuffer buff=new StringBuffer();
    buff.append(meta);
    for (    ValueMetaInterface vm : indexedVals) {
      String colName=vm.getName();
      if (meta.indexOf(colName) < 0) {
        Object[] legalVals=vm.getIndex();
        if (buff.length() > 0) {
          buff.append("String_Node_Str").append(colName).append("String_Node_Str");
        }
 else {
          buff.append(colName).append("String_Node_Str");
        }
        for (int i=0; i < legalVals.length; i++) {
          buff.append(legalVals[i].toString());
          if (i != legalVals.length - 1) {
            buff.append("String_Node_Str");
          }
        }
        buff.append("String_Node_Str");
      }
    }
    comment=before + "String_Node_Str" + buff.toString()+ "String_Node_Str"+ after;
    colFamDefToUpdate.setComment(comment);
  }
  conn.getClient().system_update_column_family(colFamDefToUpdate);
  cassandraMeta.refresh(conn);
}

Fixed version (ground truth):
/** 
 * Updates the schema information for a given column family with any fields in the supplied RowMeta that aren't defined in the schema. Abuses the schema "comment" field to store information on any indexed values that might be in the fields in the RowMeta.
 * @param conn the connection to use
 * @param colFamilyName the name of the column family to update
 * @param inputMeta the row meta containing (potentially) new fields
 * @param keyIndex the index of the key field in the row meta
 * @param cassandraMeta meta data for the cassandra column family
 * @throws Exception if a problem occurs updating the schema
 */
public static void updateCassandraMeta(CassandraConnection conn,String colFamilyName,RowMetaInterface inputMeta,int keyIndex,CassandraColumnMetaData cassandraMeta) throws Exception {
  KsDef keySpace=conn.describeKeyspace();
  List<CfDef> colFams=null;
  if (keySpace != null) {
    colFams=keySpace.getCf_defs();
  }
 else {
    throw new Exception("String_Node_Str");
  }
  CfDef colFamDefToUpdate=null;
  for (  CfDef fam : colFams) {
    String columnFamilyName=fam.getName();
    if (columnFamilyName.equals(colFamilyName)) {
      colFamDefToUpdate=fam;
      break;
    }
  }
  if (colFamDefToUpdate == null) {
    throw new Exception("String_Node_Str" + "String_Node_Str" + colFamilyName + "String_Node_Str");
  }
  String comment=colFamDefToUpdate.getComment();
  List<ValueMetaInterface> indexedVals=new ArrayList<ValueMetaInterface>();
  for (int i=0; i < inputMeta.size(); i++) {
    if (i != keyIndex) {
      ValueMetaInterface colMeta=inputMeta.getValueMeta(i);
      if (colMeta.getStorageType() == ValueMetaInterface.STORAGE_TYPE_INDEXED) {
        indexedVals.add(colMeta);
      }
      String colName=colMeta.getName();
      if (!cassandraMeta.columnExistsInSchema(colName)) {
        String colType=CassandraColumnMetaData.getCassandraTypeForValueMeta(colMeta);
        ColumnDef newCol=new ColumnDef(ByteBuffer.wrap(colName.getBytes()),colType);
        colFamDefToUpdate.addToColumn_metadata(newCol);
      }
    }
  }
  if (indexedVals.size() > 0) {
    String before="String_Node_Str";
    String after="String_Node_Str";
    String meta="String_Node_Str";
    if (comment != null && comment.length() > 0) {
      if (comment.indexOf("String_Node_Str") >= 0) {
        before=comment.substring(0,comment.indexOf("String_Node_Str"));
        after=comment.substring(comment.lastIndexOf("String_Node_Str") + 3,comment.length());
        meta=comment.substring(comment.indexOf("String_Node_Str",comment.lastIndexOf("String_Node_Str")));
        meta=meta.replace("String_Node_Str","String_Node_Str");
      }
    }
    StringBuffer buff=new StringBuffer();
    buff.append(meta);
    for (    ValueMetaInterface vm : indexedVals) {
      String colName=vm.getName();
      if (meta.indexOf(colName) < 0) {
        Object[] legalVals=vm.getIndex();
        if (buff.length() > 0) {
          buff.append("String_Node_Str").append(colName).append("String_Node_Str");
        }
 else {
          buff.append(colName).append("String_Node_Str");
        }
        for (int i=0; i < legalVals.length; i++) {
          buff.append(legalVals[i].toString());
          if (i != legalVals.length - 1) {
            buff.append("String_Node_Str");
          }
        }
        buff.append("String_Node_Str");
      }
    }
    comment=before + "String_Node_Str" + buff.toString()+ "String_Node_Str"+ after;
    colFamDefToUpdate.setComment(comment);
  }
  conn.getClient().system_update_column_family(colFamDefToUpdate);
  cassandraMeta.refresh(conn);
}