Program: 143682
Project: 143682
Buggy source:
/** 
 * @param newKey
 * @param string
 * @param string2
 */
private boolean createOrUpdateKey(String newKey,String referenceValue,String localeValue){
  boolean operationPerformed=false;
  if (Messages.invalidConnection || Messages.noConnection || referenceValue == null || "String_Node_Str".equals(referenceValue))   return operationPerformed;
  String serverName=application.getSolution().getI18nServerName();
  String tableName=application.getSolution().getI18nTableName();
  if ("String_Node_Str".equals(serverName))   serverName=null;
  if ("String_Node_Str".equals(tableName))   tableName=null;
  if (serverName == null || tableName == null) {
    Properties settings=application.getSettings();
    serverName=settings.getProperty("String_Node_Str");
    tableName=settings.getProperty("String_Node_Str");
    if ("String_Node_Str".equals(serverName))     serverName=null;
    if ("String_Node_Str".equals(tableName))     tableName=null;
    if (serverName == null || tableName == null) {
      throw new IllegalStateException("String_Node_Str");
    }
  }
  IDataServer dataServer=application.getDataServer();
  try {
    IServer i18nServer=(application.getRepository()).getServer(serverName);
    if (i18nServer == null)     throw new IllegalArgumentException("String_Node_Str" + serverName + "String_Node_Str");
    Table i18nTable=(Table)i18nServer.getTable(tableName);
    if (i18nTable == null)     throw new IllegalArgumentException("String_Node_Str" + tableName + "String_Node_Str");
    List<Column> list=i18nTable.getRowIdentColumns();
    if (list.size() > 1)     throw new IllegalArgumentException("String_Node_Str");
    if (list.size() == 0)     throw new IllegalArgumentException("String_Node_Str");
    String language=getSelectedLanguage();
    String filterColumn=null;
    String filterValue=null;
    if (application instanceof IMessagesCallback) {
      filterColumn=((IMessagesCallback)application).getI18NColumnNameFilter();
      Object v=((IMessagesCallback)application).getI18NColumnValueFilter();
      if (v instanceof String)       filterValue=(String)v;
    }
    Column pkColumn=list.get(0);
    QueryTable messagesTable=new QueryTable(i18nTable.getSQLName(),i18nTable.getCatalog(),i18nTable.getSchema());
    QueryColumn pkCol=new QueryColumn(messagesTable,pkColumn.getID(),pkColumn.getSQLName(),pkColumn.getType(),pkColumn.getLength());
    QueryColumn msgKey=new QueryColumn(messagesTable,-1,"String_Node_Str",Types.VARCHAR,150);
    QueryColumn msgLang=new QueryColumn(messagesTable,-1,"String_Node_Str",Types.VARCHAR,5);
    QueryColumn msgVal=new QueryColumn(messagesTable,-1,"String_Node_Str",Types.VARCHAR,2000);
    QueryColumn filterCol=null;
    if (filterColumn != null && filterValue != null && filterColumn.length() > 0 && filterValue.length() > 0) {
      filterCol=new QueryColumn(messagesTable,-1,filterColumn,Types.VARCHAR,2000);
    }
    TablePlaceholderKey langPlaceholderKey=new TablePlaceholderKey(messagesTable,"String_Node_Str");
    TablePlaceholderKey valuePlaceholderKey=new TablePlaceholderKey(messagesTable,"String_Node_Str");
    QuerySelect selectSQL=new QuerySelect(messagesTable);
    selectSQL.addColumn(pkCol);
    selectSQL.addCondition("String_Node_Str",new CompareCondition(ISQLCondition.EQUALS_OPERATOR,msgKey,newKey));
    selectSQL.addCondition("String_Node_Str",new CompareCondition(ISQLCondition.EQUALS_OPERATOR,msgLang,new Placeholder(langPlaceholderKey)));
    if (filterCol != null) {
      selectSQL.addCondition("String_Node_Str",new CompareCondition(ISQLCondition.EQUALS_OPERATOR,filterCol,filterValue));
    }
    boolean logIdIsServoyManaged=false;
    ColumnInfo ci=pkColumn.getColumnInfo();
    if (ci != null) {
      int autoEnterType=ci.getAutoEnterType();
      int autoEnterSubType=ci.getAutoEnterSubType();
      logIdIsServoyManaged=(autoEnterType == ColumnInfo.SEQUENCE_AUTO_ENTER) && (autoEnterSubType != ColumnInfo.NO_SEQUENCE_SELECTED) && (autoEnterSubType != ColumnInfo.DATABASE_IDENTITY);
    }
    SQLStatement statement1=null;
    SQLStatement statement2=null;
    selectSQL.setPlaceholderValue(langPlaceholderKey,ValueFactory.createNullValue(Types.VARCHAR));
    IDataSet set=dataServer.performQuery(application.getClientID(),serverName,null,selectSQL,null,false,0,25,IDataServer.MESSAGES_QUERY);
    if (set.getRowCount() == 0) {
      QueryInsert insert=new QueryInsert(messagesTable);
      Object messageId=null;
      if (logIdIsServoyManaged)       messageId=dataServer.getNextSequence(serverName,i18nTable.getName(),pkColumn.getName(),-1);
      if (filterCol == null) {
        if (logIdIsServoyManaged) {
          insert.setColumnValues(new QueryColumn[]{pkCol,msgKey,msgLang,msgVal},new Object[]{messageId,newKey,ValueFactory.createNullValue(Types.VARCHAR),referenceValue});
        }
 else {
          insert.setColumnValues(new QueryColumn[]{msgKey,msgLang,msgVal},new Object[]{newKey,ValueFactory.createNullValue(Types.VARCHAR),referenceValue});
        }
      }
 else {
        if (logIdIsServoyManaged) {
          insert.setColumnValues(new QueryColumn[]{pkCol,msgKey,msgLang,msgVal,filterCol},new Object[]{messageId,newKey,ValueFactory.createNullValue(Types.VARCHAR),referenceValue,filterValue});
        }
 else {
          insert.setColumnValues(new QueryColumn[]{msgKey,msgLang,msgVal,filterCol},new Object[]{newKey,ValueFactory.createNullValue(Types.VARCHAR),referenceValue,filterValue});
        }
      }
      statement1=new SQLStatement(ISQLActionTypes.INSERT_ACTION,serverName,tableName,null,insert);
      if (localeValue != null && !"String_Node_Str".equals(localeValue)) {
        insert=AbstractBaseQuery.deepClone(insert);
        if (logIdIsServoyManaged)         messageId=dataServer.getNextSequence(serverName,i18nTable.getName(),pkColumn.getName(),-1);
        if (filterCol == null) {
          if (logIdIsServoyManaged) {
            insert.setColumnValues(new QueryColumn[]{pkCol,msgKey,msgLang,msgVal},new Object[]{messageId,newKey,language,localeValue});
          }
 else {
            insert.setColumnValues(new QueryColumn[]{msgKey,msgLang,msgVal},new Object[]{newKey,language,localeValue});
          }
        }
 else {
          if (logIdIsServoyManaged) {
            insert.setColumnValues(new QueryColumn[]{pkCol,msgKey,msgLang,msgVal,filterCol},new Object[]{messageId,newKey,language,localeValue,filterValue});
          }
 else {
            insert.setColumnValues(new QueryColumn[]{msgKey,msgLang,msgVal,filterCol},new Object[]{newKey,language,localeValue,filterValue});
          }
        }
        statement2=new SQLStatement(ISQLActionTypes.INSERT_ACTION,serverName,tableName,null,insert);
      }
    }
 else {
      QueryUpdate update=new QueryUpdate(messagesTable);
      update.addValue(msgVal,new Placeholder(valuePlaceholderKey));
      update.addCondition(new CompareCondition(ISQLCondition.EQUALS_OPERATOR,msgKey,newKey));
      update.addCondition(new CompareCondition(ISQLCondition.EQUALS_OPERATOR,msgLang,new Placeholder(langPlaceholderKey)));
      if (filterCol != null) {
        update.addCondition(new CompareCondition(ISQLCondition.EQUALS_OPERATOR,filterCol,filterValue));
      }
      update.setPlaceholderValue(langPlaceholderKey,ValueFactory.createNullValue(Types.VARCHAR));
      update.setPlaceholderValue(valuePlaceholderKey,referenceValue);
      statement1=new SQLStatement(ISQLActionTypes.UPDATE_ACTION,serverName,tableName,null,update);
      if (localeValue != null && !"String_Node_Str".equals(localeValue)) {
        selectSQL.setPlaceholderValue(langPlaceholderKey,language);
        set=dataServer.performQuery(application.getClientID(),serverName,null,selectSQL,null,false,0,25,IDataServer.MESSAGES_QUERY);
        if (set.getRowCount() == 0) {
          QueryInsert insert=new QueryInsert(messagesTable);
          Object messageId=null;
          if (logIdIsServoyManaged)           dataServer.getNextSequence(serverName,i18nTable.getName(),pkColumn.getName(),-1);
          if (filterCol == null) {
            if (logIdIsServoyManaged) {
              insert.setColumnValues(new QueryColumn[]{pkCol,msgKey,msgLang,msgVal},new Object[]{messageId,newKey,language,localeValue});
            }
 else {
              insert.setColumnValues(new QueryColumn[]{msgKey,msgLang,msgVal},new Object[]{newKey,language,localeValue});
            }
          }
 else {
            if (logIdIsServoyManaged) {
              insert.setColumnValues(new QueryColumn[]{pkCol,msgKey,msgLang,msgVal,filterCol},new Object[]{messageId,newKey,language,localeValue,filterValue});
            }
 else {
              insert.setColumnValues(new QueryColumn[]{msgKey,msgLang,msgVal,filterCol},new Object[]{newKey,language,localeValue,filterValue});
            }
          }
          statement2=new SQLStatement(ISQLActionTypes.INSERT_ACTION,serverName,tableName,null,insert);
        }
 else {
          update=AbstractBaseQuery.deepClone(update);
          update.setPlaceholderValue(langPlaceholderKey,language);
          update.setPlaceholderValue(valuePlaceholderKey,localeValue);
          statement2=new SQLStatement(ISQLActionTypes.UPDATE_ACTION,serverName,tableName,null,update);
        }
      }
 else {
        QueryDelete delete=new QueryDelete(messagesTable);
        delete.addCondition(new CompareCondition(ISQLCondition.EQUALS_OPERATOR,msgKey,newKey));
        delete.addCondition(new CompareCondition(ISQLCondition.EQUALS_OPERATOR,msgLang,language));
        if (filterCol != null) {
          delete.addCondition(new CompareCondition(ISQLCondition.EQUALS_OPERATOR,filterCol,filterValue));
        }
        statement2=new SQLStatement(ISQLActionTypes.DELETE_ACTION,serverName,tableName,null,delete);
      }
    }
    dataServer.performUpdates(application.getClientID(),statement2 == null ? new ISQLStatement[]{statement1} : new ISQLStatement[]{statement1,statement2});
    operationPerformed=true;
  }
 catch (  Exception e) {
    Debug.error("String_Node_Str");
    Debug.error(e);
  }
  return operationPerformed;
}

Fixed version (ground truth):
/** 
 * @param newKey
 * @param string
 * @param string2
 */
private boolean createOrUpdateKey(String newKey,String referenceValue,String localeValue){
  boolean operationPerformed=false;
  if (Messages.invalidConnection || Messages.noConnection || referenceValue == null || "String_Node_Str".equals(referenceValue))   return operationPerformed;
  String serverName=application.getSolution().getI18nServerName();
  String tableName=application.getSolution().getI18nTableName();
  if ("String_Node_Str".equals(serverName))   serverName=null;
  if ("String_Node_Str".equals(tableName))   tableName=null;
  if (serverName == null || tableName == null) {
    Properties settings=application.getSettings();
    serverName=settings.getProperty("String_Node_Str");
    tableName=settings.getProperty("String_Node_Str");
    if ("String_Node_Str".equals(serverName))     serverName=null;
    if ("String_Node_Str".equals(tableName))     tableName=null;
    if (serverName == null || tableName == null) {
      throw new IllegalStateException("String_Node_Str");
    }
  }
  IDataServer dataServer=application.getDataServer();
  try {
    IServer i18nServer=(application.getRepository()).getServer(serverName);
    if (i18nServer == null)     throw new IllegalArgumentException("String_Node_Str" + serverName + "String_Node_Str");
    Table i18nTable=(Table)i18nServer.getTable(tableName);
    if (i18nTable == null)     throw new IllegalArgumentException("String_Node_Str" + tableName + "String_Node_Str");
    List<Column> list=i18nTable.getRowIdentColumns();
    if (list.size() > 1)     throw new IllegalArgumentException("String_Node_Str");
    if (list.size() == 0)     throw new IllegalArgumentException("String_Node_Str");
    String language=getSelectedLanguage();
    String filterColumn=null;
    String filterValue=null;
    if (application instanceof IMessagesCallback) {
      filterColumn=((IMessagesCallback)application).getI18NColumnNameFilter();
      Object v=((IMessagesCallback)application).getI18NColumnValueFilter();
      if (v instanceof String)       filterValue=(String)v;
    }
    Column pkColumn=list.get(0);
    QueryTable messagesTable=new QueryTable(i18nTable.getSQLName(),i18nTable.getCatalog(),i18nTable.getSchema());
    QueryColumn pkCol=new QueryColumn(messagesTable,pkColumn.getID(),pkColumn.getSQLName(),pkColumn.getType(),pkColumn.getLength());
    QueryColumn msgKey=new QueryColumn(messagesTable,-1,"String_Node_Str",Types.VARCHAR,150);
    QueryColumn msgLang=new QueryColumn(messagesTable,-1,"String_Node_Str",Types.VARCHAR,5);
    QueryColumn msgVal=new QueryColumn(messagesTable,-1,"String_Node_Str",Types.VARCHAR,2000);
    QueryColumn filterCol=null;
    if (filterColumn != null && filterValue != null && filterColumn.length() > 0 && filterValue.length() > 0) {
      filterCol=new QueryColumn(messagesTable,-1,filterColumn,Types.VARCHAR,2000);
    }
    TablePlaceholderKey langPlaceholderKey=new TablePlaceholderKey(messagesTable,"String_Node_Str");
    TablePlaceholderKey valuePlaceholderKey=new TablePlaceholderKey(messagesTable,"String_Node_Str");
    QuerySelect selectSQL=new QuerySelect(messagesTable);
    selectSQL.addColumn(pkCol);
    selectSQL.addCondition("String_Node_Str",new CompareCondition(ISQLCondition.EQUALS_OPERATOR,msgKey,newKey));
    selectSQL.addCondition("String_Node_Str",new CompareCondition(ISQLCondition.EQUALS_OPERATOR,msgLang,new Placeholder(langPlaceholderKey)));
    if (filterCol != null) {
      selectSQL.addCondition("String_Node_Str",new CompareCondition(ISQLCondition.EQUALS_OPERATOR,filterCol,filterValue));
    }
    boolean logIdIsServoyManaged=false;
    ColumnInfo ci=pkColumn.getColumnInfo();
    if (ci != null) {
      int autoEnterType=ci.getAutoEnterType();
      int autoEnterSubType=ci.getAutoEnterSubType();
      logIdIsServoyManaged=(autoEnterType == ColumnInfo.SEQUENCE_AUTO_ENTER) && (autoEnterSubType != ColumnInfo.NO_SEQUENCE_SELECTED) && (autoEnterSubType != ColumnInfo.DATABASE_IDENTITY);
    }
    SQLStatement statement1=null;
    SQLStatement statement2=null;
    selectSQL.setPlaceholderValue(langPlaceholderKey,ValueFactory.createNullValue(Types.VARCHAR));
    IDataSet set=dataServer.performQuery(application.getClientID(),serverName,null,selectSQL,null,false,0,25,IDataServer.MESSAGES_QUERY);
    if (set.getRowCount() == 0) {
      QueryInsert insert=new QueryInsert(messagesTable);
      Object messageId=null;
      if (logIdIsServoyManaged)       messageId=dataServer.getNextSequence(serverName,i18nTable.getName(),pkColumn.getName(),-1);
      if (filterCol == null) {
        if (logIdIsServoyManaged) {
          insert.setColumnValues(new QueryColumn[]{pkCol,msgKey,msgLang,msgVal},new Object[]{messageId,newKey,ValueFactory.createNullValue(Types.VARCHAR),referenceValue});
        }
 else {
          insert.setColumnValues(new QueryColumn[]{msgKey,msgLang,msgVal},new Object[]{newKey,ValueFactory.createNullValue(Types.VARCHAR),referenceValue});
        }
      }
 else {
        if (logIdIsServoyManaged) {
          insert.setColumnValues(new QueryColumn[]{pkCol,msgKey,msgLang,msgVal,filterCol},new Object[]{messageId,newKey,ValueFactory.createNullValue(Types.VARCHAR),referenceValue,filterValue});
        }
 else {
          insert.setColumnValues(new QueryColumn[]{msgKey,msgLang,msgVal,filterCol},new Object[]{newKey,ValueFactory.createNullValue(Types.VARCHAR),referenceValue,filterValue});
        }
      }
      statement1=new SQLStatement(ISQLActionTypes.INSERT_ACTION,serverName,tableName,null,insert);
      if (localeValue != null && !"String_Node_Str".equals(localeValue)) {
        insert=AbstractBaseQuery.deepClone(insert);
        if (logIdIsServoyManaged)         messageId=dataServer.getNextSequence(serverName,i18nTable.getName(),pkColumn.getName(),-1);
        if (filterCol == null) {
          if (logIdIsServoyManaged) {
            insert.setColumnValues(new QueryColumn[]{pkCol,msgKey,msgLang,msgVal},new Object[]{messageId,newKey,language,localeValue});
          }
 else {
            insert.setColumnValues(new QueryColumn[]{msgKey,msgLang,msgVal},new Object[]{newKey,language,localeValue});
          }
        }
 else {
          if (logIdIsServoyManaged) {
            insert.setColumnValues(new QueryColumn[]{pkCol,msgKey,msgLang,msgVal,filterCol},new Object[]{messageId,newKey,language,localeValue,filterValue});
          }
 else {
            insert.setColumnValues(new QueryColumn[]{msgKey,msgLang,msgVal,filterCol},new Object[]{newKey,language,localeValue,filterValue});
          }
        }
        statement2=new SQLStatement(ISQLActionTypes.INSERT_ACTION,serverName,tableName,null,insert);
      }
    }
 else {
      QueryUpdate update=new QueryUpdate(messagesTable);
      update.addValue(msgVal,new Placeholder(valuePlaceholderKey));
      update.addCondition(new CompareCondition(ISQLCondition.EQUALS_OPERATOR,msgKey,newKey));
      update.addCondition(new CompareCondition(ISQLCondition.EQUALS_OPERATOR,msgLang,new Placeholder(langPlaceholderKey)));
      if (filterCol != null) {
        update.addCondition(new CompareCondition(ISQLCondition.EQUALS_OPERATOR,filterCol,filterValue));
      }
      update.setPlaceholderValue(langPlaceholderKey,ValueFactory.createNullValue(Types.VARCHAR));
      update.setPlaceholderValue(valuePlaceholderKey,referenceValue);
      statement1=new SQLStatement(ISQLActionTypes.UPDATE_ACTION,serverName,tableName,null,update);
      if (localeValue != null && !"String_Node_Str".equals(localeValue)) {
        selectSQL.setPlaceholderValue(langPlaceholderKey,language);
        set=dataServer.performQuery(application.getClientID(),serverName,null,selectSQL,null,false,0,25,IDataServer.MESSAGES_QUERY);
        if (set.getRowCount() == 0) {
          QueryInsert insert=new QueryInsert(messagesTable);
          Object messageId=null;
          if (logIdIsServoyManaged)           messageId=dataServer.getNextSequence(serverName,i18nTable.getName(),pkColumn.getName(),-1);
          if (filterCol == null) {
            if (logIdIsServoyManaged) {
              insert.setColumnValues(new QueryColumn[]{pkCol,msgKey,msgLang,msgVal},new Object[]{messageId,newKey,language,localeValue});
            }
 else {
              insert.setColumnValues(new QueryColumn[]{msgKey,msgLang,msgVal},new Object[]{newKey,language,localeValue});
            }
          }
 else {
            if (logIdIsServoyManaged) {
              insert.setColumnValues(new QueryColumn[]{pkCol,msgKey,msgLang,msgVal,filterCol},new Object[]{messageId,newKey,language,localeValue,filterValue});
            }
 else {
              insert.setColumnValues(new QueryColumn[]{msgKey,msgLang,msgVal,filterCol},new Object[]{newKey,language,localeValue,filterValue});
            }
          }
          statement2=new SQLStatement(ISQLActionTypes.INSERT_ACTION,serverName,tableName,null,insert);
        }
 else {
          update=AbstractBaseQuery.deepClone(update);
          update.setPlaceholderValue(langPlaceholderKey,language);
          update.setPlaceholderValue(valuePlaceholderKey,localeValue);
          statement2=new SQLStatement(ISQLActionTypes.UPDATE_ACTION,serverName,tableName,null,update);
        }
      }
 else {
        QueryDelete delete=new QueryDelete(messagesTable);
        delete.addCondition(new CompareCondition(ISQLCondition.EQUALS_OPERATOR,msgKey,newKey));
        delete.addCondition(new CompareCondition(ISQLCondition.EQUALS_OPERATOR,msgLang,language));
        if (filterCol != null) {
          delete.addCondition(new CompareCondition(ISQLCondition.EQUALS_OPERATOR,filterCol,filterValue));
        }
        statement2=new SQLStatement(ISQLActionTypes.DELETE_ACTION,serverName,tableName,null,delete);
      }
    }
    dataServer.performUpdates(application.getClientID(),statement2 == null ? new ISQLStatement[]{statement1} : new ISQLStatement[]{statement1,statement2});
    operationPerformed=true;
  }
 catch (  Exception e) {
    Debug.error("String_Node_Str");
    Debug.error(e);
  }
  return operationPerformed;
}