nus-yam/ex-repair huggingface dataset:
Program: 246
Project: 246
Buggy source:
/** 
 * Moves the cursor to the line entered by the user
 * @param editor The editor to perform the action in.
 * @param context The data context
 * @param cmd The complete Ex command including range, command, and arguments
 * @return True if able to perform the command, false if not
 */
public boolean execute(Editor editor,DataContext context,ExCommand cmd){
  int count=cmd.getLine(editor,context);
  if (count > 0) {
    MotionGroup.moveCaret(editor,context,CommandGroups.getInstance().getMotion().moveCaretToLineStartSkipLeading(editor,count));
    return true;
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Moves the cursor to the line entered by the user
 * @param editor The editor to perform the action in.
 * @param context The data context
 * @param cmd The complete Ex command including range, command, and arguments
 * @return True if able to perform the command, false if not
 */
public boolean execute(Editor editor,DataContext context,ExCommand cmd){
  int count=cmd.getLine(editor,context);
  if (count >= 0) {
    MotionGroup.moveCaret(editor,context,CommandGroups.getInstance().getMotion().moveCaretToLineStartSkipLeading(editor,count));
    return true;
  }
 else {
    MotionGroup.moveCaret(editor,context,0);
  }
  return false;
}
Program: 247
Project: 247
Buggy source:
public void resetVisual(Editor editor){
  EditorData.setLastVisualRange(editor,new VisualRange(visualStart,visualEnd,CommandState.getInstance().getVisualType()));
  CommandState.getInstance().reset();
  editor.getSelectionModel().removeSelection();
}

Fixed version (ground truth):
public void resetVisual(Editor editor){
  EditorData.setLastVisualRange(editor,new VisualRange(visualStart,visualEnd,CommandState.getInstance().getVisualType()));
  editor.getSelectionModel().removeSelection();
  CommandState.getInstance().setVisualType(0);
}
Program: 248
Project: 248
Buggy source:
public void setVisualMode(Editor editor,DataContext context,int mode){
  int oldMode=CommandState.getInstance().getVisualType();
  if (mode == 0) {
    int start=editor.getSelectionModel().getSelectionStart();
    int end=editor.getSelectionModel().getSelectionEnd();
    if (start != end) {
      int line=editor.offsetToLogicalPosition(start).line;
      int lstart=EditorHelper.getLineStartOffset(editor,line);
      int lend=EditorHelper.getLineEndOffset(editor,line,true);
      logger.debug("String_Node_Str" + start + "String_Node_Str"+ end+ "String_Node_Str"+ lstart+ "String_Node_Str"+ lend);
      if (lstart == start && lend + 1 == end) {
        mode=Command.FLAG_MOT_LINEWISE;
      }
 else {
        mode=Command.FLAG_MOT_CHARACTERWISE;
      }
    }
  }
  if (oldMode == 0 && mode == 0) {
    editor.getSelectionModel().removeSelection();
    return;
  }
  CommandState.getInstance().setVisualType(mode);
  if (mode == 0) {
    resetVisual(editor);
  }
 else {
    CommandState.getInstance().setMode(CommandState.MODE_VISUAL);
    CommandState.getInstance().setMappingMode(KeyParser.MAPPING_VISUAL);
  }
  KeyHandler.getInstance().reset();
  visualStart=editor.getSelectionModel().getSelectionStart();
  visualEnd=editor.getSelectionModel().getSelectionEnd();
  CommandGroups.getInstance().getMark().setMark(editor,context,'<',visualStart);
  CommandGroups.getInstance().getMark().setMark(editor,context,'>',visualEnd);
}

Fixed version (ground truth):
public void setVisualMode(Editor editor,DataContext context,int mode){
  int oldMode=CommandState.getInstance().getVisualType();
  if (mode == 0) {
    int start=editor.getSelectionModel().getSelectionStart();
    int end=editor.getSelectionModel().getSelectionEnd();
    if (start != end) {
      int line=editor.offsetToLogicalPosition(start).line;
      int lstart=EditorHelper.getLineStartOffset(editor,line);
      int lend=EditorHelper.getLineEndOffset(editor,line,true);
      logger.debug("String_Node_Str" + start + "String_Node_Str"+ end+ "String_Node_Str"+ lstart+ "String_Node_Str"+ lend);
      if (lstart == start && lend + 1 == end) {
        mode=Command.FLAG_MOT_LINEWISE;
      }
 else {
        mode=Command.FLAG_MOT_CHARACTERWISE;
      }
    }
  }
  if (oldMode == 0 && mode == 0) {
    editor.getSelectionModel().removeSelection();
    return;
  }
  CommandState.getInstance().setVisualType(mode);
  if (mode == 0) {
    exitVisual(editor);
  }
 else {
    CommandState.getInstance().setMode(CommandState.MODE_VISUAL);
    CommandState.getInstance().setMappingMode(KeyParser.MAPPING_VISUAL);
  }
  KeyHandler.getInstance().reset();
  visualStart=editor.getSelectionModel().getSelectionStart();
  visualEnd=editor.getSelectionModel().getSelectionEnd();
  CommandGroups.getInstance().getMark().setMark(editor,context,'<',visualStart);
  CommandGroups.getInstance().getMark().setMark(editor,context,'>',visualEnd);
}
Program: 250
Project: 250
Buggy source:
public boolean toggleVisual(Editor editor,DataContext context,int mode){
  int currentMode=CommandState.getInstance().getVisualType();
  if (currentMode == 0) {
    CommandState.getInstance().setMode(CommandState.MODE_VISUAL);
    CommandState.getInstance().setVisualType(mode);
    CommandState.getInstance().setMappingMode(KeyParser.MAPPING_VISUAL);
    visualStart=editor.getSelectionModel().getSelectionStart();
    updateSelection(editor,context,visualStart);
  }
 else   if (mode == currentMode) {
    resetVisual(editor);
  }
 else {
    CommandState.getInstance().setVisualType(mode);
    updateSelection(editor,context,visualEnd);
  }
  return true;
}

Fixed version (ground truth):
public boolean toggleVisual(Editor editor,DataContext context,int mode){
  int currentMode=CommandState.getInstance().getVisualType();
  if (currentMode == 0) {
    CommandState.getInstance().setMode(CommandState.MODE_VISUAL);
    CommandState.getInstance().setVisualType(mode);
    CommandState.getInstance().setMappingMode(KeyParser.MAPPING_VISUAL);
    visualStart=editor.getSelectionModel().getSelectionStart();
    updateSelection(editor,context,visualStart);
  }
 else   if (mode == currentMode) {
    exitVisual(editor);
  }
 else {
    CommandState.getInstance().setVisualType(mode);
    updateSelection(editor,context,visualEnd);
  }
  return true;
}
Program: 251
Project: 251
Buggy source:
public TextRange getTextRange(Editor editor,DataContext context,int count){
  LineRange lr=getLineRange(editor,context,count);
  int start=editor.getDocument().getLineStartOffset(lr.getStartLine());
  int end=editor.getDocument().getLineEndOffset(lr.getEndLine()) + 1;
  return new TextRange(start,Math.min(end,EditorHelper.getFileSize(editor)));
}

Fixed version (ground truth):
public TextRange getTextRange(Editor editor,DataContext context,int count){
  LineRange lr=getLineRange(editor,context,count);
  int start=EditorHelper.getLineStartOffset(editor,lr.getStartLine());
  int end=EditorHelper.getLineEndOffset(editor,lr.getEndLine()) + 1;
  return new TextRange(start,Math.min(end,EditorHelper.getFileSize(editor)));
}
Program: 252
Project: 252
Buggy source:
public boolean execute(Editor editor,DataContext context,ExCommand cmd) throws ExException {
  char mark=cmd.getArgument().charAt(0);
  int line=cmd.getLine(editor,context);
  int offset=editor.getDocument().getLineStartOffset(line);
  return CommandGroups.getInstance().getMark().setMark(editor,context,mark,offset);
}

Fixed version (ground truth):
public boolean execute(Editor editor,DataContext context,ExCommand cmd) throws ExException {
  char mark=cmd.getArgument().charAt(0);
  int line=cmd.getLine(editor,context);
  int offset=EditorHelper.getLineStartOffset(editor,line);
  return CommandGroups.getInstance().getMark().setMark(editor,context,mark,offset);
}
Program: 253
Project: 253
Buggy source:
public boolean execute(Editor editor,DataContext context,ExCommand cmd) throws ExException {
  int line=cmd.getLine(editor,context);
  String arg=cmd.getArgument();
  boolean before=false;
  if (arg.length() > 0 && arg.charAt(0) == '!') {
    before=true;
    arg=arg.substring(1).trim();
  }
  if (arg.length() > 0) {
    CommandGroups.getInstance().getRegister().selectRegister(arg.charAt(0));
  }
 else {
    CommandGroups.getInstance().getRegister().selectRegister(RegisterGroup.REGISTER_DEFAULT);
  }
  MotionGroup.moveCaret(editor,context,editor.getDocument().getLineStartOffset(line));
  if (before) {
    return CommandGroups.getInstance().getCopy().putTextBeforeCursor(editor,context,1);
  }
 else {
    return CommandGroups.getInstance().getCopy().putTextAfterCursor(editor,context,1);
  }
}

Fixed version (ground truth):
public boolean execute(Editor editor,DataContext context,ExCommand cmd) throws ExException {
  int line=cmd.getLine(editor,context);
  String arg=cmd.getArgument();
  boolean before=false;
  if (arg.length() > 0 && arg.charAt(0) == '!') {
    before=true;
    arg=arg.substring(1).trim();
  }
  if (arg.length() > 0) {
    CommandGroups.getInstance().getRegister().selectRegister(arg.charAt(0));
  }
 else {
    CommandGroups.getInstance().getRegister().selectRegister(RegisterGroup.REGISTER_DEFAULT);
  }
  MotionGroup.moveCaret(editor,context,EditorHelper.getLineStartOffset(editor,line));
  if (before) {
    return CommandGroups.getInstance().getCopy().putTextBeforeCursor(editor,context,1);
  }
 else {
    return CommandGroups.getInstance().getCopy().putTextAfterCursor(editor,context,1);
  }
}
Program: 255
Project: 255
Buggy source:
/** 
 * Each character in the supplied range gets replaced with the character ch
 * @param editor The editor to change
 * @param context The data context
 * @param range The range to change
 * @param ch The replacing character
 * @return true if able to change the range, false if not
 */
public boolean changeCharacterRange(Editor editor,DataContext context,TextRange range,char ch){
  char[] chars=editor.getDocument().getChars();
  for (int i=range.getStartOffset(); i < range.getEndOffset(); i++) {
    if ('\n' != chars[i]) {
      replaceText(editor,context,i,i + 1,Character.toString(ch));
    }
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Each character in the supplied range gets replaced with the character ch
 * @param editor The editor to change
 * @param context The data context
 * @param range The range to change
 * @param ch The replacing character
 * @return true if able to change the range, false if not
 */
public boolean changeCharacterRange(Editor editor,DataContext context,TextRange range,char ch){
  char[] chars=editor.getDocument().getChars();
  for (int i=range.getStartOffset(); i < range.getEndOffset(); i++) {
    if (i < chars.length && '\n' != chars[i]) {
      replaceText(editor,context,i,i + 1,Character.toString(ch));
    }
  }
  return true;
}
Program: 256
Project: 256
Buggy source:
/** 
 * This performs the actual case change.
 * @param editor The editor to change
 * @param context The data context
 * @param start The start offset to change
 * @param end The end offset to change
 * @param type The type of change (TOGGLE, UPPER, LOWER)
 */
private void changeCase(Editor editor,DataContext context,int start,int end,char type){
  if (start > end) {
    int t=end;
    end=start;
    start=t;
  }
  char[] chars=editor.getDocument().getChars();
  for (int i=start; i < end; i++) {
    char ch=CharacterHelper.changeCase(chars[i],type);
    if (ch != chars[i]) {
      replaceText(editor,context,i,i + 1,Character.toString(ch));
    }
  }
}

Fixed version (ground truth):
/** 
 * This performs the actual case change.
 * @param editor The editor to change
 * @param context The data context
 * @param start The start offset to change
 * @param end The end offset to change
 * @param type The type of change (TOGGLE, UPPER, LOWER)
 */
private void changeCase(Editor editor,DataContext context,int start,int end,char type){
  if (start > end) {
    int t=end;
    end=start;
    start=t;
  }
  char[] chars=editor.getDocument().getChars();
  for (int i=start; i < end; i++) {
    if (i >= chars.length) {
      break;
    }
    char ch=CharacterHelper.changeCase(chars[i],type);
    if (ch != chars[i]) {
      replaceText(editor,context,i,i + 1,Character.toString(ch));
    }
  }
}
Program: 257
Project: 257
Buggy source:
/** 
 * Delete all text moved over by the supplied motion command argument.
 * @param editor The editor to delete the text from
 * @param context The data context
 * @param count The number of times to repear the deletion
 * @param rawCount The actual count entered by the user
 * @param argument The motion command
 * @return true if able to delete the text, false if not
 */
public boolean deleteMotion(Editor editor,DataContext context,int count,int rawCount,Argument argument){
  TextRange range=MotionGroup.getMotionRange(editor,context,count,rawCount,argument,false);
  return deleteRange(editor,context,range,argument.getMotion().getFlags());
}

Fixed version (ground truth):
/** 
 * Delete all text moved over by the supplied motion command argument.
 * @param editor The editor to delete the text from
 * @param context The data context
 * @param count The number of times to repear the deletion
 * @param rawCount The actual count entered by the user
 * @param argument The motion command
 * @return true if able to delete the text, false if not
 */
public boolean deleteMotion(Editor editor,DataContext context,int count,int rawCount,Argument argument){
  TextRange range=MotionGroup.getMotionRange(editor,context,count,rawCount,argument,false);
  if (range == null && EditorHelper.getFileSize(editor) == 0) {
    return true;
  }
  return deleteRange(editor,context,range,argument.getMotion().getFlags());
}
Program: 258
Project: 258
Buggy source:
/** 
 * Delete the text covered by the motion command argument and enter insert mode
 * @param editor The editor to change
 * @param context The data context
 * @param count The number of time to repeat the change
 * @param rawCount The actual count entered by the user
 * @param argument The motion command
 * @return true if able to delete the text, false if not
 */
public boolean changeMotion(Editor editor,DataContext context,int count,int rawCount,Argument argument){
  String id=ActionManager.getInstance().getId(argument.getMotion().getAction());
  if (id.equals("String_Node_Str")) {
    if (!Character.isWhitespace(editor.getDocument().getChars()[editor.getCaretModel().getOffset()])) {
      argument.getMotion().setAction(ActionManager.getInstance().getAction("String_Node_Str"));
      argument.getMotion().setFlags(MotionGroup.INCLUSIVE);
    }
  }
 else   if (id.equals("String_Node_Str")) {
    if (!Character.isWhitespace(editor.getDocument().getChars()[editor.getCaretModel().getOffset()])) {
      argument.getMotion().setAction(ActionManager.getInstance().getAction("String_Node_Str"));
      argument.getMotion().setFlags(MotionGroup.INCLUSIVE);
    }
  }
  boolean res=deleteMotion(editor,context,count,rawCount,argument);
  if (res) {
    insertBeforeCursor(editor,context);
  }
  return res;
}

Fixed version (ground truth):
/** 
 * Delete the text covered by the motion command argument and enter insert mode
 * @param editor The editor to change
 * @param context The data context
 * @param count The number of time to repeat the change
 * @param rawCount The actual count entered by the user
 * @param argument The motion command
 * @return true if able to delete the text, false if not
 */
public boolean changeMotion(Editor editor,DataContext context,int count,int rawCount,Argument argument){
  String id=ActionManager.getInstance().getId(argument.getMotion().getAction());
  if (id.equals("String_Node_Str")) {
    if (EditorHelper.getFileSize(editor) > 0 && !Character.isWhitespace(editor.getDocument().getChars()[editor.getCaretModel().getOffset()])) {
      argument.getMotion().setAction(ActionManager.getInstance().getAction("String_Node_Str"));
      argument.getMotion().setFlags(MotionGroup.INCLUSIVE);
    }
  }
 else   if (id.equals("String_Node_Str")) {
    if (EditorHelper.getFileSize(editor) > 0 && !Character.isWhitespace(editor.getDocument().getChars()[editor.getCaretModel().getOffset()])) {
      argument.getMotion().setAction(ActionManager.getInstance().getAction("String_Node_Str"));
      argument.getMotion().setFlags(MotionGroup.INCLUSIVE);
    }
  }
  boolean res=deleteMotion(editor,context,count,rawCount,argument);
  if (res) {
    insertBeforeCursor(editor,context);
  }
  return res;
}
Program: 260
Project: 260
Buggy source:
public int moveCaretToLineEnd(Editor editor,int lline){
  int offset=EditorHelper.normalizeOffset(editor,lline,editor.getDocument().getLineEndOffset(lline) - 1,false);
  return offset;
}

Fixed version (ground truth):
public int moveCaretToLineEnd(Editor editor,int lline){
  int offset=EditorHelper.normalizeOffset(editor,lline,EditorHelper.getLineEndOffset(editor,lline) - 1,false);
  return offset;
}
Program: 261
Project: 261
Buggy source:
public int moveCaretToLinePercent(Editor editor,DataContext context,int count){
  if (count > 100)   count=100;
  saveJumpLocation(editor,context);
  return moveCaretToLineStartSkipLeading(editor,EditorHelper.normalizeLine(editor,(EditorHelper.getLineCount(editor) * count + 99) / 100) - 1);
}

Fixed version (ground truth):
public int moveCaretToLinePercent(Editor editor,DataContext context,int count){
  if (count > 100)   count=100;
  saveJumpLocation(editor,context);
  return moveCaretToLineStartSkipLeading(editor,EditorHelper.normalizeLine(editor,(EditorHelper.getLineCount(editor) * count + 99) / 100 - 1));
}
Program: 262
Project: 262
Buggy source:
public int moveCaretToLineEndSkipLeading(Editor editor,int lline){
  int start=editor.getDocument().getLineStartOffset(lline);
  int end=editor.getDocument().getLineEndOffset(lline);
  char[] chars=editor.getDocument().getChars();
  int pos=start;
  for (int offset=end; offset > start; offset--) {
    if (!Character.isWhitespace(chars[offset])) {
      pos=offset;
      break;
    }
  }
  return pos;
}

Fixed version (ground truth):
public int moveCaretToLineEndSkipLeading(Editor editor,int lline){
  int start=EditorHelper.getLineStartOffset(editor,lline);
  int end=EditorHelper.getLineEndOffset(editor,lline);
  char[] chars=editor.getDocument().getChars();
  int pos=start;
  for (int offset=end; offset > start; offset--) {
    if (offset >= chars.length) {
      break;
    }
    if (!Character.isWhitespace(chars[offset])) {
      pos=offset;
      break;
    }
  }
  return pos;
}
Program: 263
Project: 263
Buggy source:
public int moveCaretToLineEndAppendOffset(Editor editor,int cntForward){
  int line=EditorHelper.normalizeVisualLine(editor,EditorHelper.getCurrentVisualLine(editor) + cntForward);
  return editor.getDocument().getLineEndOffset(EditorHelper.visualLineToLogicalLine(editor,line));
}

Fixed version (ground truth):
public int moveCaretToLineEndAppendOffset(Editor editor,int cntForward){
  int line=EditorHelper.normalizeVisualLine(editor,EditorHelper.getCurrentVisualLine(editor) + cntForward);
  return EditorHelper.getLineEndOffset(editor,EditorHelper.visualLineToLogicalLine(editor,line));
}
Program: 264
Project: 264
Buggy source:
public static void moveCaret(Editor editor,DataContext context,int offset){
  if (offset >= 0) {
    editor.getCaretModel().moveToOffset(offset);
    EditorData.setLastColumn(editor,editor.getCaretModel().getVisualPosition().column);
    editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
    if (CommandState.getInstance().getMode() == CommandState.MODE_VISUAL) {
      CommandGroups.getInstance().getMotion().updateSelection(editor,context,offset);
    }
 else {
      editor.getSelectionModel().removeSelection();
    }
  }
}

Fixed version (ground truth):
public static void moveCaret(Editor editor,DataContext context,int offset){
  if (offset >= 0 && offset < editor.getDocument().getTextLength()) {
    editor.getCaretModel().moveToOffset(offset);
    EditorData.setLastColumn(editor,editor.getCaretModel().getVisualPosition().column);
    editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
    if (CommandState.getInstance().getMode() == CommandState.MODE_VISUAL) {
      CommandGroups.getInstance().getMotion().updateSelection(editor,context,offset);
    }
 else {
      editor.getSelectionModel().removeSelection();
    }
  }
}
Program: 265
Project: 265
Buggy source:
public int moveCaretGotoLineLast(Editor editor,DataContext context,int rawCount,int lline){
  saveJumpLocation(editor,context);
  return moveCaretToLineStartSkipLeading(editor,rawCount == 0 ? EditorHelper.getLineCount(editor) - 1 : lline);
}

Fixed version (ground truth):
public int moveCaretGotoLineLast(Editor editor,DataContext context,int rawCount,int lline){
  saveJumpLocation(editor,context);
  return moveCaretToLineStartSkipLeading(editor,rawCount == 0 ? EditorHelper.normalizeLine(editor,EditorHelper.getLineCount(editor) - 1) : lline);
}
Program: 266
Project: 266
Buggy source:
public int moveCaretToLineStartSkipLeading(Editor editor,int lline){
  int start=editor.getDocument().getLineStartOffset(lline);
  int end=editor.getDocument().getLineEndOffset(lline);
  char[] chars=editor.getDocument().getChars();
  int pos=end;
  for (int offset=start; offset < end; offset++) {
    if (!Character.isWhitespace(chars[offset])) {
      pos=offset;
      break;
    }
  }
  return pos;
}

Fixed version (ground truth):
public int moveCaretToLineStartSkipLeading(Editor editor,int lline){
  int start=EditorHelper.getLineStartOffset(editor,lline);
  int end=EditorHelper.getLineEndOffset(editor,lline);
  char[] chars=editor.getDocument().getChars();
  int pos=end;
  for (int offset=start; offset < end; offset++) {
    if (offset >= chars.length) {
      break;
    }
    if (!Character.isWhitespace(chars[offset])) {
      pos=offset;
      break;
    }
  }
  return pos;
}
Program: 267
Project: 267
Buggy source:
public void setVisualMode(Editor editor,DataContext context,int mode){
  int oldMode=CommandState.getInstance().getVisualType();
  if (mode == 0) {
    int start=editor.getSelectionModel().getSelectionStart();
    int end=editor.getSelectionModel().getSelectionEnd();
    if (start != end) {
      int line=editor.offsetToLogicalPosition(start).line;
      int lstart=editor.getDocument().getLineStartOffset(line);
      int lend=editor.getDocument().getLineEndOffset(line);
      logger.debug("String_Node_Str" + start + "String_Node_Str"+ end+ "String_Node_Str"+ lstart+ "String_Node_Str"+ lend);
      if (lstart == start && lend + 1 == end) {
        mode=LINEWISE;
      }
 else {
        mode=CHARACTERWISE;
      }
    }
  }
  if (oldMode == 0 && mode == 0) {
    editor.getSelectionModel().removeSelection();
    return;
  }
  CommandState.getInstance().setVisualType(mode);
  if (mode == 0) {
    resetVisual(editor);
  }
 else {
    CommandState.getInstance().setMode(CommandState.MODE_VISUAL);
    CommandState.getInstance().setMappingMode(KeyParser.MAPPING_VISUAL);
  }
  KeyHandler.getInstance().reset();
  visualStart=editor.getSelectionModel().getSelectionStart();
  visualEnd=editor.getSelectionModel().getSelectionEnd();
  CommandGroups.getInstance().getMark().setMark(editor,context,'<',visualStart);
  CommandGroups.getInstance().getMark().setMark(editor,context,'>',visualEnd);
}

Fixed version (ground truth):
public void setVisualMode(Editor editor,DataContext context,int mode){
  int oldMode=CommandState.getInstance().getVisualType();
  if (mode == 0) {
    int start=editor.getSelectionModel().getSelectionStart();
    int end=editor.getSelectionModel().getSelectionEnd();
    if (start != end) {
      int line=editor.offsetToLogicalPosition(start).line;
      int lstart=EditorHelper.getLineStartOffset(editor,line);
      int lend=EditorHelper.getLineEndOffset(editor,line);
      logger.debug("String_Node_Str" + start + "String_Node_Str"+ end+ "String_Node_Str"+ lstart+ "String_Node_Str"+ lend);
      if (lstart == start && lend + 1 == end) {
        mode=LINEWISE;
      }
 else {
        mode=CHARACTERWISE;
      }
    }
  }
  if (oldMode == 0 && mode == 0) {
    editor.getSelectionModel().removeSelection();
    return;
  }
  CommandState.getInstance().setVisualType(mode);
  if (mode == 0) {
    resetVisual(editor);
  }
 else {
    CommandState.getInstance().setMode(CommandState.MODE_VISUAL);
    CommandState.getInstance().setMappingMode(KeyParser.MAPPING_VISUAL);
  }
  KeyHandler.getInstance().reset();
  visualStart=editor.getSelectionModel().getSelectionStart();
  visualEnd=editor.getSelectionModel().getSelectionEnd();
  CommandGroups.getInstance().getMark().setMark(editor,context,'<',visualStart);
  CommandGroups.getInstance().getMark().setMark(editor,context,'>',visualEnd);
}
Program: 268
Project: 268
Buggy source:
public int moveCaretGotoLineLastEndAppend(Editor editor,DataContext context,int rawCount,int lline){
  saveJumpLocation(editor,context);
  return moveCaretToLineEndAppend(editor,rawCount == 0 ? EditorHelper.getLineCount(editor) - 1 : lline);
}

Fixed version (ground truth):
public int moveCaretGotoLineLastEndAppend(Editor editor,DataContext context,int rawCount,int lline){
  saveJumpLocation(editor,context);
  return moveCaretToLineEndAppend(editor,rawCount == 0 ? EditorHelper.normalizeLine(editor,EditorHelper.getLineCount(editor) - 1) : lline);
}
Program: 269
Project: 269
Buggy source:
public int moveCaretGotoLineLastEnd(Editor editor,DataContext context,int rawCount,int lline){
  saveJumpLocation(editor,context);
  return moveCaretToLineEnd(editor,rawCount == 0 ? EditorHelper.getLineCount(editor) - 1 : lline);
}

Fixed version (ground truth):
public int moveCaretGotoLineLastEnd(Editor editor,DataContext context,int rawCount,int lline){
  saveJumpLocation(editor,context);
  return moveCaretToLineEnd(editor,rawCount == 0 ? EditorHelper.normalizeLine(editor,EditorHelper.getLineCount(editor) - 1) : lline);
}
Program: 270
Project: 270
Buggy source:
public int moveCaretToLineStart(Editor editor,int lline){
  if (lline >= EditorHelper.getLineCount(editor)) {
    return EditorHelper.getFileSize(editor);
  }
  int start=editor.getDocument().getLineStartOffset(lline);
  return start;
}

Fixed version (ground truth):
public int moveCaretToLineStart(Editor editor,int lline){
  if (lline >= EditorHelper.getLineCount(editor)) {
    return EditorHelper.getFileSize(editor);
  }
  int start=EditorHelper.getLineStartOffset(editor,lline);
  return start;
}
Program: 271
Project: 271
Buggy source:
/** 
 * This moves the caret to the end of the next/previous word/WORD.
 * @param count The number of words to skip
 * @param skipPunc If true then find WORD, if false then find word
 * @param editor The editor to move in
 */
public int moveCaretToNextWordEnd(Editor editor,int count,boolean skipPunc){
  int pos=SearchHelper.findNextWordEnd(editor,count,skipPunc);
  if (pos == -1) {
    if (count < 0) {
      return moveCaretToLineStart(editor,0);
    }
 else {
      return moveCaretToLineEnd(editor,EditorHelper.getLineCount(editor) - 1);
    }
  }
 else {
    return pos;
  }
}

Fixed version (ground truth):
/** 
 * This moves the caret to the end of the next/previous word/WORD.
 * @param count The number of words to skip
 * @param skipPunc If true then find WORD, if false then find word
 * @param editor The editor to move in
 */
public int moveCaretToNextWordEnd(Editor editor,int count,boolean skipPunc){
  if ((editor.getCaretModel().getOffset() == 0 && count < 0) || (editor.getCaretModel().getOffset() >= EditorHelper.getFileSize(editor) - 1 && count > 0)) {
    return -1;
  }
  int pos=SearchHelper.findNextWordEnd(editor,count,skipPunc);
  if (pos == -1) {
    if (count < 0) {
      return moveCaretToLineStart(editor,0);
    }
 else {
      return moveCaretToLineEnd(editor,EditorHelper.getLineCount(editor) - 1);
    }
  }
 else {
    return pos;
  }
}
Program: 272
Project: 272
Buggy source:
/** 
 * Gets the number of visible lines in the editor. This will less then the actuall number of lines in the file if there are any collapsed folds.
 * @param editor The editor
 * @return The number of visible lines in the file
 */
public static int getVisualLineCount(Editor editor){
  return logicalLineToVisualLine(editor,getLineCount(editor));
}

Fixed version (ground truth):
/** 
 * Gets the number of visible lines in the editor. This will less then the actual number of lines in the file if there are any collapsed folds.
 * @param editor The editor
 * @return The number of visible lines in the file
 */
public static int getVisualLineCount(Editor editor){
  int count=getLineCount(editor);
  return count == 0 ? 0 : logicalLineToVisualLine(editor,count - 1) + 1;
}
Program: 273
Project: 273
Buggy source:
/** 
 * Ensures that the supplied logical line is within the range 0 (incl) and the number of logical lines in the file (excl).
 * @param editor The editor
 * @param lline The logical line number to normalize
 * @return The normalized logical line number
 */
public static int normalizeLine(Editor editor,int lline){
  lline=Math.min(Math.max(0,lline),getLineCount(editor) - 1);
  return lline;
}

Fixed version (ground truth):
/** 
 * Ensures that the supplied logical line is within the range 0 (incl) and the number of logical lines in the file (excl).
 * @param editor The editor
 * @param lline The logical line number to normalize
 * @return The normalized logical line number
 */
public static int normalizeLine(Editor editor,int lline){
  lline=Math.max(0,Math.min(lline,getLineCount(editor) - 1));
  return lline;
}
Program: 274
Project: 274
Buggy source:
@Override public void onOpened(){
  try {
    if (findWorldByName().getWorldGenerator() == null) {
      worldGenerator=WorldGeneratorManager.createWorldGenerator(findWorldByName().getWorldGeneratorInfo().getUri(),context,environment);
      findWorldByName().setWorldGenerator(worldGenerator);
    }
 else {
      worldGenerator=findWorldByName().getWorldGenerator();
    }
    if (worldGenerator.getWorldSeed().isEmpty()) {
      worldGenerator.setWorldSeed(createSeed(selectedWorld));
    }
    previewGen=new FacetLayerPreview(environment,worldGenerator);
    updatePreview();
  }
 catch (  UnresolvedWorldGeneratorException e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
@Override public void onOpened(){
  try {
    if (findWorldByName(selectedWorld).getWorldGenerator() == null) {
      worldGenerator=WorldGeneratorManager.createWorldGenerator(findWorldByName(selectedWorld).getWorldGeneratorInfo().getUri(),context,environment);
      findWorldByName(selectedWorld).setWorldGenerator(worldGenerator);
    }
 else {
      worldGenerator=findWorldByName(selectedWorld).getWorldGenerator();
    }
    if (worldGenerator.getWorldSeed().isEmpty()) {
      worldGenerator.setWorldSeed(createSeed(selectedWorld));
    }
    previewGen=new FacetLayerPreview(environment,worldGenerator);
    updatePreview();
  }
 catch (  UnresolvedWorldGeneratorException e) {
    e.printStackTrace();
  }
}
Program: 275
Project: 275
Buggy source:
/** 
 * This method takes the name of the world selected in the worldsDropdown as String and return the corresponding WorldSetupWrapper object.
 * @return {@link WorldSetupWrapper} object of the selected world.
 */
private WorldSetupWrapper findWorldByName(){
  for (  WorldSetupWrapper world : worldList) {
    if (world.getWorldName().toString().equals(selectedWorld)) {
      return world;
    }
  }
  return null;
}

Fixed version (ground truth):
/** 
 * This method takes the name of the world selected in the worldsDropdown as String and return the corresponding WorldSetupWrapper object.
 * @return {@link WorldSetupWrapper} object of the selected world.
 */
private WorldSetupWrapper findWorldByName(String searchWorld){
  for (  WorldSetupWrapper world : worldList) {
    if (world.getWorldName().toString().equals(searchWorld)) {
      return world;
    }
  }
  return null;
}
Program: 276
Project: 276
Buggy source:
@Override public void set(String value){
  selectedWorld=value;
  try {
    if (findWorldByName().getWorldGenerator() == null) {
      worldGenerator=WorldGeneratorManager.createWorldGenerator(findWorldByName().getWorldGeneratorInfo().getUri(),context,environment);
      findWorldByName().setWorldGenerator(worldGenerator);
    }
 else {
      worldGenerator=findWorldByName().getWorldGenerator();
    }
    if (worldGenerator.getWorldSeed() == null) {
      worldGenerator.setWorldSeed(createSeed(selectedWorld));
    }
    previewGen=new FacetLayerPreview(environment,worldGenerator);
    updatePreview();
  }
 catch (  UnresolvedWorldGeneratorException e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
@Override public void set(String value){
  selectedWorld=value;
  try {
    if (findWorldByName(selectedWorld).getWorldGenerator() == null) {
      worldGenerator=WorldGeneratorManager.createWorldGenerator(findWorldByName(selectedWorld).getWorldGeneratorInfo().getUri(),context,environment);
      findWorldByName(selectedWorld).setWorldGenerator(worldGenerator);
    }
 else {
      worldGenerator=findWorldByName(selectedWorld).getWorldGenerator();
    }
    if (worldGenerator.getWorldSeed() == null) {
      worldGenerator.setWorldSeed(createSeed(selectedWorld));
    }
    previewGen=new FacetLayerPreview(environment,worldGenerator);
    updatePreview();
  }
 catch (  UnresolvedWorldGeneratorException e) {
    e.printStackTrace();
  }
}
Program: 278
Project: 278
Buggy source:
private void setWorldGenerators(){
  for (  WorldSetupWrapper worldSetupWrapper : worldList) {
    if (worldSetupWrapper.getWorldGenerator() == null) {
      try {
        worldSetupWrapper.setWorldGenerator(WorldGeneratorManager.createWorldGenerator(findWorldByName().getWorldGeneratorInfo().getUri(),context,environment));
      }
 catch (      UnresolvedWorldGeneratorException e) {
        e.printStackTrace();
      }
    }
    worldSetupWrapper.getWorldGenerator().setWorldSeed(createSeed(worldSetupWrapper.getWorldName().toString()));
  }
}

Fixed version (ground truth):
private void setWorldGenerators(){
  for (  WorldSetupWrapper worldSetupWrapper : worldList) {
    if (worldSetupWrapper.getWorldGenerator() == null) {
      try {
        worldSetupWrapper.setWorldGenerator(WorldGeneratorManager.createWorldGenerator(findWorldByName(worldSetupWrapper.getWorldName().toString()).getWorldGeneratorInfo().getUri(),context,environment));
      }
 catch (      UnresolvedWorldGeneratorException e) {
        e.printStackTrace();
      }
    }
    worldSetupWrapper.getWorldGenerator().setWorldSeed(createSeed(worldSetupWrapper.getWorldName().toString()));
  }
}
Program: 279
Project: 279
Buggy source:
/** 
 * A function called before the screen comes to the forefront to setup the environment and extract necessary objects from the new Context.
 * @param subContext The new environment created in {@link UniverseSetupScreen}
 * @throws UnresolvedWorldGeneratorException The creation of a world generator can throw this Exception
 */
public void setEnvironment(Context subContext) throws UnresolvedWorldGeneratorException {
  context=subContext;
  environment=context.get(ModuleEnvironment.class);
  context.put(WorldGeneratorPluginLibrary.class,new TempWorldGeneratorPluginLibrary(environment,context));
  worldList=context.get(UniverseSetupScreen.class).getWorldsList();
  selectedWorld=context.get(UniverseSetupScreen.class).getSelectedWorld();
  worldNames=context.get(UniverseSetupScreen.class).worldNames();
  setWorldGenerators();
  worldGenerator=findWorldByName().getWorldGenerator();
  final UIDropdownScrollable worldsDropdown=find("String_Node_Str",UIDropdownScrollable.class);
  worldsDropdown.setOptions(worldNames);
  genTexture();
  List<Zone> previewZones=Lists.newArrayList(worldGenerator.getZones()).stream().filter(z -> !z.getPreviewLayers().isEmpty()).collect(Collectors.toList());
  if (previewZones.isEmpty()) {
    previewGen=new FacetLayerPreview(environment,worldGenerator);
  }
}

Fixed version (ground truth):
/** 
 * A function called before the screen comes to the forefront to setup the environment and extract necessary objects from the new Context.
 * @param subContext The new environment created in {@link UniverseSetupScreen}
 * @throws UnresolvedWorldGeneratorException The creation of a world generator can throw this Exception
 */
public void setEnvironment(Context subContext) throws UnresolvedWorldGeneratorException {
  context=subContext;
  environment=context.get(ModuleEnvironment.class);
  context.put(WorldGeneratorPluginLibrary.class,new TempWorldGeneratorPluginLibrary(environment,context));
  worldList=context.get(UniverseSetupScreen.class).getWorldsList();
  selectedWorld=context.get(UniverseSetupScreen.class).getSelectedWorld();
  worldNames=context.get(UniverseSetupScreen.class).worldNames();
  setWorldGenerators();
  worldGenerator=findWorldByName(selectedWorld).getWorldGenerator();
  final UIDropdownScrollable worldsDropdown=find("String_Node_Str",UIDropdownScrollable.class);
  worldsDropdown.setOptions(worldNames);
  genTexture();
  List<Zone> previewZones=Lists.newArrayList(worldGenerator.getZones()).stream().filter(z -> !z.getPreviewLayers().isEmpty()).collect(Collectors.toList());
  if (previewZones.isEmpty()) {
    previewGen=new FacetLayerPreview(environment,worldGenerator);
  }
}
Program: 280
Project: 280
Buggy source:
private void advancedModuleFilter(){
  Iterator<ModuleSelectionInfo> iter=sortedModules.iterator();
  while (iter.hasNext()) {
    ModuleSelectionInfo m=iter.next();
    Module module;
    if (m.isPresent()) {
      module=moduleManager.getRegistry().getLatestModuleVersion(m.getMetadata().getId());
    }
 else {
      module=(m.getOnlineVersion() == null) ? m.getLatestVersion() : m.getOnlineVersion();
    }
    boolean matches=false;
    Collection<StandardModuleExtension> selectedStandardModuleExtensions=selectModulesConfig.getSelectedStandardModuleExtensions();
    for (    StandardModuleExtension standardModuleExtension : selectedStandardModuleExtensions) {
      if (standardModuleExtension.isProvidedBy(module)) {
        matches=true;
        break;
      }
    }
    if (!matches) {
      iter.remove();
    }
  }
}

Fixed version (ground truth):
private void advancedModuleFilter(){
  Iterator<ModuleSelectionInfo> iter=sortedModules.iterator();
  while (iter.hasNext()) {
    ModuleSelectionInfo m=iter.next();
    Module module;
    if (m.isPresent()) {
      module=moduleManager.getRegistry().getLatestModuleVersion(m.getMetadata().getId());
    }
 else {
      module=(m.getOnlineVersion() == null) ? m.getLatestVersion() : m.getOnlineVersion();
    }
    boolean matches=false;
    Collection<StandardModuleExtension> selectedStandardModuleExtensions=selectModulesConfig.getSelectedStandardModuleExtensions();
    for (    StandardModuleExtension standardModuleExtension : selectedStandardModuleExtensions) {
      if (standardModuleExtension != null && standardModuleExtension.isProvidedBy(module)) {
        matches=true;
        break;
      }
    }
    if (!matches) {
      iter.remove();
    }
  }
}
Program: 284
Project: 284
Buggy source:
@Override public void initialise(){
  WidgetUtil.trySubscribe(this,"String_Node_Str",button -> triggerBackAnimation());
  WidgetUtil.trySubscribe(this,"String_Node_Str",button -> {
    final GameManifest gameManifest=GameManifestProvider.createGameManifest(universeWrapper,moduleManager,config);
    if (gameManifest != null) {
      gameEngine.changeState(new StateLoading(gameManifest,(universeWrapper.getLoadingAsServer()) ? NetworkMode.DEDICATED_SERVER : NetworkMode.NONE));
    }
 else {
      getManager().createScreen(MessagePopup.ASSET_URI,MessagePopup.class).setMessage("String_Node_Str","String_Node_Str");
    }
    SimpleUri uri;
    WorldInfo worldInfo;
    int i=0;
    for (    WorldSetupWrapper world : worldSetupWrappers) {
      if (world != targetWorld) {
        i++;
        uri=world.getWorldGeneratorInfo().getUri();
        worldInfo=new WorldInfo(TerasologyConstants.MAIN_WORLD + i,world.getWorldGenerator().getWorldSeed(),(long)(WorldTime.DAY_LENGTH * WorldTime.NOON_OFFSET),uri);
        gameManifest.addWorld(worldInfo);
      }
    }
    gameEngine.changeState(new StateLoading(gameManifest,(universeWrapper.getLoadingAsServer()) ? NetworkMode.DEDICATED_SERVER : NetworkMode.NONE));
  }
);
}

Fixed version (ground truth):
@Override public void initialise(){
  WidgetUtil.trySubscribe(this,"String_Node_Str",button -> triggerBackAnimation());
  WidgetUtil.trySubscribe(this,"String_Node_Str",button -> {
    universeWrapper.setTargetWorld(targetWorld);
    final GameManifest gameManifest=GameManifestProvider.createGameManifest(universeWrapper,moduleManager,config);
    if (gameManifest != null) {
      gameEngine.changeState(new StateLoading(gameManifest,(universeWrapper.getLoadingAsServer()) ? NetworkMode.DEDICATED_SERVER : NetworkMode.NONE));
    }
 else {
      getManager().createScreen(MessagePopup.ASSET_URI,MessagePopup.class).setMessage("String_Node_Str","String_Node_Str");
    }
    SimpleUri uri;
    WorldInfo worldInfo;
    int i=0;
    for (    WorldSetupWrapper world : worldSetupWrappers) {
      if (world != targetWorld) {
        i++;
        uri=world.getWorldGeneratorInfo().getUri();
        worldInfo=new WorldInfo(TerasologyConstants.MAIN_WORLD + i,world.getWorldGenerator().getWorldSeed(),(long)(WorldTime.DAY_LENGTH * WorldTime.NOON_OFFSET),uri);
        gameManifest.addWorld(worldInfo);
      }
    }
    gameEngine.changeState(new StateLoading(gameManifest,(universeWrapper.getLoadingAsServer()) ? NetworkMode.DEDICATED_SERVER : NetworkMode.NONE));
  }
);
}
Program: 285
Project: 285
Buggy source:
@Override public EntityRef copy(EntityRef other){
  if (!other.exists()) {
    return EntityRef.NULL;
  }
  List<Component> newEntityComponents=Lists.newArrayList();
  for (  Component c : other.iterateComponents()) {
    newEntityComponents.add(componentLibrary.copy(c));
  }
  return globalPool.create(newEntityComponents);
}

Fixed version (ground truth):
@Override public EntityRef copy(EntityRef other){
  if (!other.exists()) {
    return EntityRef.NULL;
  }
  List<Component> newEntityComponents=Lists.newArrayList();
  for (  Component c : other.iterateComponents()) {
    newEntityComponents.add(componentLibrary.copy(c));
  }
  return getCurrentWorldPool().create(newEntityComponents);
}
Program: 287
Project: 287
Buggy source:
private void setUpLocalPlayer(Context context){
  LocalPlayer localPlayer=new LocalPlayer();
  localPlayer.setEntityIdMap(new EntityIdMap());
  clientEntity=mock(EntityRef.class);
  ClientComponent clientComponent=new ClientComponent();
  characterEntity=mock(EntityRef.class);
  clientComponent.character=characterEntity;
  when(clientEntity.getComponent(ClientComponent.class)).thenReturn(clientComponent);
  localPlayer.setClientEntity(clientEntity);
  context.put(LocalPlayer.class,localPlayer);
  registerEntityKeyCapturing();
}

Fixed version (ground truth):
private void setUpLocalPlayer(Context context){
  LocalPlayer localPlayer=new LocalPlayer();
  localPlayer.setRecordAndReplayClasses(new EntityIdMap(),new DirectionAndOriginPosRecorderList());
  clientEntity=mock(EntityRef.class);
  ClientComponent clientComponent=new ClientComponent();
  characterEntity=mock(EntityRef.class);
  clientComponent.character=characterEntity;
  when(clientEntity.getComponent(ClientComponent.class)).thenReturn(clientComponent);
  localPlayer.setClientEntity(clientEntity);
  context.put(LocalPlayer.class,localPlayer);
  registerEntityKeyCapturing();
}
Program: 294
Project: 294
Buggy source:
@Override public void init(GameEngine gameEngine){
  context=gameEngine.createChildContext();
  CoreRegistry.setContext(context);
  EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
  entityManager=context.get(EngineEntityManager.class);
  eventSystem=context.get(EventSystem.class);
  context.put(Console.class,new ConsoleImpl(context));
  NUIManager nuiManager=new NUIManagerInternal(context.get(CanvasRenderer.class),context);
  context.put(NUIManager.class,nuiManager);
  componentSystemManager=new ComponentSystemManager(context);
  context.put(ComponentSystemManager.class,componentSystemManager);
  componentSystemManager.register(new ConsoleSystem(),"String_Node_Str");
  componentSystemManager.register(new CoreCommands(),"String_Node_Str");
  componentSystemManager.register(context.get(InputSystem.class),"String_Node_Str");
  EntityRef localPlayerEntity=entityManager.create(new ClientComponent());
  LocalPlayer localPlayer=new LocalPlayer();
  localPlayer.setEntityIdMap(context.get(EntityIdMap.class));
  context.put(LocalPlayer.class,localPlayer);
  localPlayer.setClientEntity(localPlayerEntity);
  componentSystemManager.initialise();
  GameManifest gameManifest;
  List<GameInfo> savedGames=GameProvider.getSavedGames();
  if (savedGames.size() > 0) {
    gameManifest=savedGames.get(0).getManifest();
  }
 else {
    gameManifest=createGameManifest();
  }
  gameEngine.changeState(new StateLoading(gameManifest,NetworkMode.LISTEN_SERVER));
}

Fixed version (ground truth):
@Override public void init(GameEngine gameEngine){
  context=gameEngine.createChildContext();
  CoreRegistry.setContext(context);
  EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
  entityManager=context.get(EngineEntityManager.class);
  eventSystem=context.get(EventSystem.class);
  context.put(Console.class,new ConsoleImpl(context));
  NUIManager nuiManager=new NUIManagerInternal(context.get(CanvasRenderer.class),context);
  context.put(NUIManager.class,nuiManager);
  componentSystemManager=new ComponentSystemManager(context);
  context.put(ComponentSystemManager.class,componentSystemManager);
  componentSystemManager.register(new ConsoleSystem(),"String_Node_Str");
  componentSystemManager.register(new CoreCommands(),"String_Node_Str");
  componentSystemManager.register(context.get(InputSystem.class),"String_Node_Str");
  EntityRef localPlayerEntity=entityManager.create(new ClientComponent());
  LocalPlayer localPlayer=new LocalPlayer();
  localPlayer.setRecordAndReplayClasses(context.get(EntityIdMap.class),context.get(DirectionAndOriginPosRecorderList.class));
  context.put(LocalPlayer.class,localPlayer);
  localPlayer.setClientEntity(localPlayerEntity);
  componentSystemManager.initialise();
  GameManifest gameManifest;
  List<GameInfo> savedGames=GameProvider.getSavedGames();
  if (savedGames.size() > 0) {
    gameManifest=savedGames.get(0).getManifest();
  }
 else {
    gameManifest=createGameManifest();
  }
  gameEngine.changeState(new StateLoading(gameManifest,NetworkMode.LISTEN_SERVER));
}