Program: 143702
Project: 143702
Buggy source:
public static void writeMessagesToRepository(String i18NServerName,String i18NTableName,IRepository repository,IDataServer dataServer,String clientID,TreeMap<String,MessageEntry> messages,boolean noUpdates,boolean noRemoves) throws Exception {
  TreeMap<String,MessageEntry> remoteMessages=loadSortedMessagesFromRepository(repository,dataServer,clientID,i18NServerName,i18NTableName);
  if (remoteMessages != null) {
    IServer i18NServer=repository.getServer(i18NServerName);
    Table i18NTable=null;
    if (i18NServer != null) {
      i18NTable=(Table)i18NServer.getTable(i18NTableName);
    }
    if (i18NTable != null) {
      Column pkColumn=null;
      List<Column> list=i18NTable.getRowIdentColumns();
      if (list.size() > 0) {
        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 msgLang=new QueryColumn(messagesTable,-1,"String_Node_Str",Types.VARCHAR,5);
      QueryColumn msgKey=new QueryColumn(messagesTable,-1,"String_Node_Str",Types.VARCHAR,150);
      QueryColumn msgVal=new QueryColumn(messagesTable,-1,"String_Node_Str",Types.VARCHAR,2000);
      ArrayList<SQLStatement> updateStatements=new ArrayList<SQLStatement>();
      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);
      }
      Iterator<Map.Entry<String,MessageEntry>> messagesIte=messages.entrySet().iterator();
      Map.Entry<String,MessageEntry> messageEntry;
      while (messagesIte.hasNext()) {
        messageEntry=messagesIte.next();
        String key=messageEntry.getKey();
        String value=messageEntry.getValue().getValue();
        String lang=messageEntry.getValue().getLanguage();
        if (lang.equals("String_Node_Str"))         lang=null;
        String messageKey=messageEntry.getValue().getKey();
        if (!remoteMessages.containsKey(key)) {
          QueryInsert insert=new QueryInsert(messagesTable);
          if (logIdIsServoyManaged) {
            Object messageId=dataServer.getNextSequence(i18NServerName,i18NTableName,pkColumn.getName(),-1);
            if (lang == null)             insert.setColumnValues(new QueryColumn[]{pkCol,msgKey,msgVal},new Object[]{messageId,messageKey,value});
 else             insert.setColumnValues(new QueryColumn[]{pkCol,msgKey,msgLang,msgVal},new Object[]{messageId,messageKey,lang,value});
          }
 else {
            if (lang == null)             insert.setColumnValues(new QueryColumn[]{msgKey,msgVal},new Object[]{messageKey,value});
 else             insert.setColumnValues(new QueryColumn[]{msgKey,msgLang,msgVal},new Object[]{messageKey,lang,value});
          }
          updateStatements.add(new SQLStatement(ISQLStatement.INSERT_ACTION,i18NServerName,i18NTableName,null,insert));
        }
 else         if (!remoteMessages.get(key).equals(value) && !noUpdates) {
          QueryUpdate update=new QueryUpdate(messagesTable);
          update.addValue(msgVal,value);
          update.addCondition(new CompareCondition(ISQLCondition.EQUALS_OPERATOR,msgKey,messageKey));
          update.addCondition(new CompareCondition(ISQLCondition.EQUALS_OPERATOR,msgLang,lang));
          updateStatements.add(new SQLStatement(ISQLStatement.UPDATE_ACTION,i18NServerName,i18NTableName,null,update));
        }
      }
      if (!noRemoves) {
        Iterator<Map.Entry<String,MessageEntry>> remoteMessagesIte=remoteMessages.entrySet().iterator();
        Map.Entry<String,MessageEntry> remoteMessageEntry;
        while (remoteMessagesIte.hasNext()) {
          remoteMessageEntry=remoteMessagesIte.next();
          String key=remoteMessageEntry.getKey();
          if (!messages.containsKey(key)) {
            String lang=remoteMessageEntry.getValue().getLanguage();
            if (lang.equals("String_Node_Str"))             lang=null;
            String messageKey=remoteMessageEntry.getValue().getKey();
            QueryDelete delete=new QueryDelete(messagesTable);
            delete.addCondition(new CompareCondition(ISQLCondition.EQUALS_OPERATOR,msgKey,messageKey));
            delete.addCondition(new CompareCondition(ISQLCondition.EQUALS_OPERATOR,msgLang,lang));
            updateStatements.add(new SQLStatement(ISQLStatement.DELETE_ACTION,i18NServerName,i18NTableName,null,delete));
          }
        }
      }
      dataServer.performUpdates(clientID,updateStatements.toArray(new ISQLStatement[updateStatements.size()]));
      Messages.changedTime=System.currentTimeMillis();
    }
  }
}

Fixed version (ground truth):
public static void writeMessagesToRepository(String i18NServerName,String i18NTableName,IRepository repository,IDataServer dataServer,String clientID,TreeMap<String,MessageEntry> messages,boolean noUpdates,boolean noRemoves) throws Exception {
  TreeMap<String,MessageEntry> remoteMessages=loadSortedMessagesFromRepository(repository,dataServer,clientID,i18NServerName,i18NTableName);
  if (remoteMessages != null) {
    IServer i18NServer=repository.getServer(i18NServerName);
    Table i18NTable=null;
    if (i18NServer != null) {
      i18NTable=(Table)i18NServer.getTable(i18NTableName);
    }
    if (i18NTable != null) {
      Column pkColumn=i18NTable.getRowIdentColumns().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 msgLang=new QueryColumn(messagesTable,-1,"String_Node_Str",Types.VARCHAR,5);
      QueryColumn msgKey=new QueryColumn(messagesTable,-1,"String_Node_Str",Types.VARCHAR,150);
      QueryColumn msgVal=new QueryColumn(messagesTable,-1,"String_Node_Str",Types.VARCHAR,2000);
      ArrayList<SQLStatement> updateStatements=new ArrayList<SQLStatement>();
      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);
      }
      Iterator<Map.Entry<String,MessageEntry>> messagesIte=messages.entrySet().iterator();
      Map.Entry<String,MessageEntry> messageEntry;
      while (messagesIte.hasNext()) {
        messageEntry=messagesIte.next();
        String key=messageEntry.getKey();
        String value=messageEntry.getValue().getValue();
        String lang=messageEntry.getValue().getLanguage();
        if (lang.equals("String_Node_Str"))         lang=null;
        String messageKey=messageEntry.getValue().getKey();
        if (!remoteMessages.containsKey(key)) {
          QueryInsert insert=new QueryInsert(messagesTable);
          if (logIdIsServoyManaged) {
            Object messageId=dataServer.getNextSequence(i18NServerName,i18NTableName,pkColumn.getName(),-1);
            if (lang == null)             insert.setColumnValues(new QueryColumn[]{pkCol,msgKey,msgVal},new Object[]{messageId,messageKey,value});
 else             insert.setColumnValues(new QueryColumn[]{pkCol,msgKey,msgLang,msgVal},new Object[]{messageId,messageKey,lang,value});
          }
 else {
            if (lang == null)             insert.setColumnValues(new QueryColumn[]{msgKey,msgVal},new Object[]{messageKey,value});
 else             insert.setColumnValues(new QueryColumn[]{msgKey,msgLang,msgVal},new Object[]{messageKey,lang,value});
          }
          updateStatements.add(new SQLStatement(ISQLActionTypes.INSERT_ACTION,i18NServerName,i18NTableName,null,insert));
        }
 else         if (!remoteMessages.get(key).getValue().equals(value) && !noUpdates) {
          QueryUpdate update=new QueryUpdate(messagesTable);
          update.addValue(msgVal,value);
          update.addCondition(new CompareCondition(ISQLCondition.EQUALS_OPERATOR,msgKey,messageKey));
          update.addCondition(new CompareCondition(ISQLCondition.EQUALS_OPERATOR,msgLang,lang));
          updateStatements.add(new SQLStatement(ISQLActionTypes.UPDATE_ACTION,i18NServerName,i18NTableName,null,update));
        }
      }
      if (!noRemoves) {
        Iterator<Map.Entry<String,MessageEntry>> remoteMessagesIte=remoteMessages.entrySet().iterator();
        Map.Entry<String,MessageEntry> remoteMessageEntry;
        while (remoteMessagesIte.hasNext()) {
          remoteMessageEntry=remoteMessagesIte.next();
          String key=remoteMessageEntry.getKey();
          if (!messages.containsKey(key)) {
            String lang=remoteMessageEntry.getValue().getLanguage();
            if (lang.equals("String_Node_Str"))             lang=null;
            String messageKey=remoteMessageEntry.getValue().getKey();
            QueryDelete delete=new QueryDelete(messagesTable);
            delete.addCondition(new CompareCondition(ISQLCondition.EQUALS_OPERATOR,msgKey,messageKey));
            delete.addCondition(new CompareCondition(ISQLCondition.EQUALS_OPERATOR,msgLang,lang));
            updateStatements.add(new SQLStatement(ISQLActionTypes.DELETE_ACTION,i18NServerName,i18NTableName,null,delete));
          }
        }
      }
      dataServer.performUpdates(clientID,updateStatements.toArray(new ISQLStatement[updateStatements.size()]));
      Messages.changedTime=System.currentTimeMillis();
    }
  }
}