Program: 47764
Project: 47764
Buggy source:
private void saveMapping(){
  if (Const.isEmpty(m_existingTableNamesCombo.getText().trim()) || Const.isEmpty(m_existingMappingNamesCombo.getText().trim())) {
    MessageDialog.openError(m_shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str"));
    return;
  }
  if (m_fieldsView.nrNonEmpty() == 0) {
    MessageDialog.openError(m_shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str"));
    return;
  }
  Mapping theMapping=new Mapping(m_existingTableNamesCombo.getText().trim(),m_existingMappingNamesCombo.getText().trim());
  boolean keyDefined=false;
  boolean moreThanOneKey=false;
  List<String> missingFamilies=new ArrayList<String>();
  List<String> missingColumnNames=new ArrayList<String>();
  List<String> missingTypes=new ArrayList<String>();
  int nrNonEmpty=m_fieldsView.nrNonEmpty();
  for (int i=0; i < nrNonEmpty; i++) {
    TableItem item=m_fieldsView.getNonEmpty(i);
    boolean isKey=false;
    String alias=null;
    if (!Const.isEmpty(item.getText(1))) {
      alias=item.getText(1).trim();
    }
    if (!Const.isEmpty(item.getText(2))) {
      isKey=item.getText(2).trim().equalsIgnoreCase("String_Node_Str");
      if (isKey && keyDefined) {
        moreThanOneKey=true;
        break;
      }
      if (isKey) {
        keyDefined=true;
      }
    }
    String family=null;
    if (!Const.isEmpty(item.getText(3))) {
      family=item.getText(3);
    }
 else {
      if (!isKey) {
        missingFamilies.add(item.getText(0));
      }
    }
    String colName=null;
    if (!Const.isEmpty(item.getText(4))) {
      colName=item.getText(4);
    }
 else {
      if (!isKey) {
        missingColumnNames.add(item.getText(0));
      }
    }
    String type=null;
    if (!Const.isEmpty(item.getText(5))) {
      type=item.getText(5);
    }
 else {
      missingTypes.add(item.getText(0));
    }
    String indexedVals=null;
    if (!Const.isEmpty(item.getText(6))) {
      indexedVals=item.getText(6);
    }
    if (isKey && !moreThanOneKey) {
      if (Const.isEmpty(alias)) {
      }
      if (Const.isEmpty(type)) {
      }
      if (moreThanOneKey) {
        MessageDialog.openError(m_shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str"));
        return;
      }
      theMapping.setKeyName(alias);
      try {
        theMapping.setKeyTypeAsString(type);
      }
 catch (      Exception ex) {
      }
    }
 else {
      if (missingFamilies.size() == 0 && missingColumnNames.size() == 0 && missingTypes.size() == 0) {
        String combinedName=family + HBaseValueMeta.SEPARATOR + colName;
        if (!Const.isEmpty(alias)) {
          combinedName+=(HBaseValueMeta.SEPARATOR + alias);
        }
        HBaseValueMeta vm=new HBaseValueMeta(combinedName,0,-1,-1);
        try {
          vm.setHBaseTypeFromString(type);
        }
 catch (        IllegalArgumentException e) {
          return;
        }
        if (vm.isString() && indexedVals != null && indexedVals.length() > 0) {
          Object[] vals=HBaseValueMeta.stringIndexListToObjects(indexedVals);
          vm.setIndex(vals);
          vm.setStorageType(ValueMetaInterface.STORAGE_TYPE_INDEXED);
        }
        try {
          theMapping.addMappedColumn(vm);
        }
 catch (        Exception ex) {
          MessageDialog.openError(m_shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str") + family + HBaseValueMeta.SEPARATOR+ colName+ Messages.getString("String_Node_Str"));
          ex.printStackTrace();
          return;
        }
      }
    }
  }
  if (!keyDefined) {
    MessageDialog.openError(m_shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str"));
    return;
  }
  if (missingFamilies.size() > 0 || missingColumnNames.size() > 0 || missingTypes.size() > 0) {
    StringBuffer buff=new StringBuffer();
    buff.append(Messages.getString("String_Node_Str") + "String_Node_Str");
    if (missingFamilies.size() > 0) {
      buff.append(Messages.getString("String_Node_Str") + "String_Node_Str");
      buff.append(missingFamilies.toString()).append("String_Node_Str");
    }
    if (missingColumnNames.size() > 0) {
      buff.append(Messages.getString("String_Node_Str") + "String_Node_Str");
      buff.append(missingColumnNames.toString()).append("String_Node_Str");
    }
    if (missingTypes.size() > 0) {
      buff.append(Messages.getString("String_Node_Str") + "String_Node_Str");
      buff.append(missingTypes.toString()).append("String_Node_Str");
    }
    MessageDialog.openError(m_shell,Messages.getString("String_Node_Str"),buff.toString());
    return;
  }
  if (m_allowTableCreate) {
  }
  try {
    if (m_admin.mappingExists(m_existingTableNamesCombo.getText().trim(),m_existingMappingNamesCombo.getText().trim())) {
      boolean result=MessageDialog.openConfirm(m_shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str") + m_existingMappingNamesCombo.getText().trim() + Messages.getString("String_Node_Str")+ m_existingTableNamesCombo.getText().trim()+ Messages.getString("String_Node_Str"));
      if (!result) {
        return;
      }
    }
    m_admin.putMapping(theMapping,true);
    MessageDialog.openConfirm(m_shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str") + m_existingMappingNamesCombo.getText().trim() + Messages.getString("String_Node_Str")+ m_existingTableNamesCombo.getText().trim()+ Messages.getString("String_Node_Str"));
  }
 catch (  IOException ex) {
    new ErrorDialog(m_shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str"),ex);
    ex.printStackTrace();
  }
}

Fixed version (ground truth):
private void saveMapping(){
  if (Const.isEmpty(m_existingTableNamesCombo.getText().trim()) || Const.isEmpty(m_existingMappingNamesCombo.getText().trim())) {
    MessageDialog.openError(m_shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str"));
    return;
  }
  if (m_fieldsView.nrNonEmpty() == 0) {
    MessageDialog.openError(m_shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str"));
    return;
  }
  Mapping theMapping=new Mapping(m_existingTableNamesCombo.getText().trim(),m_existingMappingNamesCombo.getText().trim());
  boolean keyDefined=false;
  boolean moreThanOneKey=false;
  List<String> missingFamilies=new ArrayList<String>();
  List<String> missingColumnNames=new ArrayList<String>();
  List<String> missingTypes=new ArrayList<String>();
  int nrNonEmpty=m_fieldsView.nrNonEmpty();
  for (int i=0; i < nrNonEmpty; i++) {
    TableItem item=m_fieldsView.getNonEmpty(i);
    boolean isKey=false;
    String alias=null;
    if (!Const.isEmpty(item.getText(1))) {
      alias=item.getText(1).trim();
    }
    if (!Const.isEmpty(item.getText(2))) {
      isKey=item.getText(2).trim().equalsIgnoreCase("String_Node_Str");
      if (isKey && keyDefined) {
        moreThanOneKey=true;
        break;
      }
      if (isKey) {
        keyDefined=true;
      }
    }
    String family=null;
    if (!Const.isEmpty(item.getText(3))) {
      family=item.getText(3);
    }
 else {
      if (!isKey) {
        missingFamilies.add(item.getText(0));
      }
    }
    String colName=null;
    if (!Const.isEmpty(item.getText(4))) {
      colName=item.getText(4);
    }
 else {
      if (!isKey) {
        missingColumnNames.add(item.getText(0));
      }
    }
    String type=null;
    if (!Const.isEmpty(item.getText(5))) {
      type=item.getText(5);
    }
 else {
      missingTypes.add(item.getText(0));
    }
    String indexedVals=null;
    if (!Const.isEmpty(item.getText(6))) {
      indexedVals=item.getText(6);
    }
    if (isKey && !moreThanOneKey) {
      if (Const.isEmpty(alias)) {
        MessageDialog.openError(m_shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str"));
        return;
      }
      if (Const.isEmpty(type)) {
        MessageDialog.openError(m_shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str"));
        return;
      }
      if (moreThanOneKey) {
        MessageDialog.openError(m_shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str"));
        return;
      }
      theMapping.setKeyName(alias);
      try {
        theMapping.setKeyTypeAsString(type);
      }
 catch (      Exception ex) {
      }
    }
 else {
      if (missingFamilies.size() == 0 && missingColumnNames.size() == 0 && missingTypes.size() == 0) {
        String combinedName=family + HBaseValueMeta.SEPARATOR + colName;
        if (!Const.isEmpty(alias)) {
          combinedName+=(HBaseValueMeta.SEPARATOR + alias);
        }
        HBaseValueMeta vm=new HBaseValueMeta(combinedName,0,-1,-1);
        try {
          vm.setHBaseTypeFromString(type);
        }
 catch (        IllegalArgumentException e) {
          return;
        }
        if (vm.isString() && indexedVals != null && indexedVals.length() > 0) {
          Object[] vals=HBaseValueMeta.stringIndexListToObjects(indexedVals);
          vm.setIndex(vals);
          vm.setStorageType(ValueMetaInterface.STORAGE_TYPE_INDEXED);
        }
        try {
          theMapping.addMappedColumn(vm);
        }
 catch (        Exception ex) {
          MessageDialog.openError(m_shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str") + family + HBaseValueMeta.SEPARATOR+ colName+ Messages.getString("String_Node_Str"));
          ex.printStackTrace();
          return;
        }
      }
    }
  }
  if (!keyDefined) {
    MessageDialog.openError(m_shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str"));
    return;
  }
  if (missingFamilies.size() > 0 || missingColumnNames.size() > 0 || missingTypes.size() > 0) {
    StringBuffer buff=new StringBuffer();
    buff.append(Messages.getString("String_Node_Str") + "String_Node_Str");
    if (missingFamilies.size() > 0) {
      buff.append(Messages.getString("String_Node_Str") + "String_Node_Str");
      buff.append(missingFamilies.toString()).append("String_Node_Str");
    }
    if (missingColumnNames.size() > 0) {
      buff.append(Messages.getString("String_Node_Str") + "String_Node_Str");
      buff.append(missingColumnNames.toString()).append("String_Node_Str");
    }
    if (missingTypes.size() > 0) {
      buff.append(Messages.getString("String_Node_Str") + "String_Node_Str");
      buff.append(missingTypes.toString()).append("String_Node_Str");
    }
    MessageDialog.openError(m_shell,Messages.getString("String_Node_Str"),buff.toString());
    return;
  }
  if (m_allowTableCreate) {
    Configuration conf=m_admin.getConnection();
    try {
      HBaseAdmin admin=new HBaseAdmin(conf);
      String tableName=m_existingTableNamesCombo.getText().trim();
      if (!admin.tableExists(tableName)) {
        boolean result=MessageDialog.openConfirm(m_shell,"String_Node_Str","String_Node_Str" + tableName + "String_Node_Str");
        if (!result) {
          return;
        }
        if (theMapping.getMappedColumns().size() == 0) {
          MessageDialog.openError(m_shell,"String_Node_Str","String_Node_Str");
          return;
        }
        Set<String> cols=theMapping.getMappedColumns().keySet();
        Set<String> families=new TreeSet<String>();
        for (        String col : cols) {
          String family=theMapping.getMappedColumns().get(col).getColumnFamily();
          families.add(family);
        }
        HTableDescriptor tableDescription=new HTableDescriptor(tableName);
        for (        String familyName : families) {
          HColumnDescriptor colDescriptor=new HColumnDescriptor(familyName);
          tableDescription.addFamily(colDescriptor);
        }
        admin.createTable(tableDescription);
        populateTableCombo(true);
      }
    }
 catch (    IOException ex) {
      new ErrorDialog(m_shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str") + "String_Node_Str" + m_existingTableNamesCombo.getText().trim()+ "String_Node_Str",ex);
      return;
    }
  }
  try {
    if (m_admin.mappingExists(m_existingTableNamesCombo.getText().trim(),m_existingMappingNamesCombo.getText().trim())) {
      boolean result=MessageDialog.openConfirm(m_shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str") + m_existingMappingNamesCombo.getText().trim() + Messages.getString("String_Node_Str")+ m_existingTableNamesCombo.getText().trim()+ Messages.getString("String_Node_Str"));
      if (!result) {
        return;
      }
    }
    m_admin.putMapping(theMapping,true);
    MessageDialog.openConfirm(m_shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str") + m_existingMappingNamesCombo.getText().trim() + Messages.getString("String_Node_Str")+ m_existingTableNamesCombo.getText().trim()+ Messages.getString("String_Node_Str"));
  }
 catch (  IOException ex) {
    new ErrorDialog(m_shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str"),ex);
    ex.printStackTrace();
  }
}