Program: 151598
Project: 151598
Buggy source:
private int prompt(final LineBuffer lineBuffer,final PipeOut out,final StringBuilder lastPattern) throws IOException {
  boolean backwards=false;
  do {
    String topBottomIndicator;
    if (lineBuffer.getCurrentLine() - shell.getHeight() + 1 == 0) {
      topBottomIndicator="String_Node_Str";
    }
 else     if (lineBuffer.atEnd()) {
      topBottomIndicator="String_Node_Str";
    }
 else {
      topBottomIndicator="String_Node_Str";
    }
    String prompt=MOREPROMPT + "String_Node_Str" + lineBuffer.getCurrentLine()+ topBottomIndicator+ "String_Node_Str";
    String bottomLineReset=new Ansi().cursor(shell.getHeight(),0).toString();
    out.print(bottomLineReset);
    out.print(attr(47,40,1));
    out.print(prompt);
    out.print(attr(0));
    out.print(bottomLineReset);
    shell.flushBuffer();
    int scanCode=shell.scan();
    shell.clearLine();
switch (scanCode) {
case 'e':
case 'E':
case 'j':
case 'J':
case 16:
      lineBuffer.rewindBuffer(shell.getHeight() - 1,lineBuffer.getCurrentLine() - 1);
    lineBuffer.setLineWidth(shell.getWidth());
  return -1;
case 'u':
case 'U':
lineBuffer.rewindBuffer(shell.getHeight() - 1,lineBuffer.getCurrentLine() - shell.getHeight());
lineBuffer.setLineWidth(shell.getWidth());
return -1;
case 'y':
case 'Y':
case 'k':
case 'K':
case 14:
case '\n':
lineBuffer.setLineWidth(shell.getWidth());
return -2;
case ' ':
lineBuffer.setLineWidth(shell.getWidth());
return -3;
case 'q':
case 'Q':
shell.clearLine();
shell.cursorLeft(prompt.length());
shell.flushBuffer();
return 0;
case '?':
backwards=true;
case '/':
shell.clearLine();
shell.cursorLeft(prompt.length());
prompt=backwards ? SEARCH_BACKWARDS_PROMPT : SEARCH_FORWARD_PROMPT;
String pattern;
if (lastPattern != null) {
prompt+="String_Node_Str" + lastPattern + "String_Node_Str";
}
out.print(ShellColor.BOLD,prompt);
shell.flushBuffer();
pattern=shell.promptAndSwallowCR().trim();
String searched;
shell.clearLine();
shell.cursorLeft(prompt.length() + pattern.length());
prompt+="String_Node_Str";
out.print(ShellColor.BOLD,prompt);
shell.flushBuffer();
String p;
if (pattern.equals("String_Node_Str") && (lastPattern.length() != 0)) {
p=searched=lineBuffer.toString();
}
 else {
if (lastPattern.length() != 0) {
lastPattern.delete(0,lastPattern.length() - 1);
}
lastPattern.append(pattern);
p=searched=pattern;
}
int result=lineBuffer.findPattern(p,backwards);
if (result == -1) {
shell.clearLine();
shell.cursorLeft(prompt.length());
shell.print(ShellColor.RED,PATTERN_NOT_FOUND + searched);
shell.flushBuffer();
shell.scan();
shell.clearLine();
shell.cursorLeft(PATTERN_NOT_FOUND.length() + searched.length());
shell.flushBuffer();
}
 else {
lineBuffer.rewindBuffer(shell.getHeight() - 1,result);
shell.clear();
shell.flushBuffer();
return -1;
}
break;
default :
shell.clearLine();
shell.cursorLeft(prompt.length());
out.print(ShellColor.RED,INVALID_COMMAND + ((char)scanCode));
shell.scan();
shell.clearLine();
shell.cursorLeft(INVALID_COMMAND.length() + 1);
}
}
 while (true);
}

Fixed version (ground truth):
private int prompt(final LineBuffer lineBuffer,final PipeOut out,final StringBuilder lastPattern) throws IOException {
  boolean backwards=false;
  do {
    String topBottomIndicator;
    if (lineBuffer.getCurrentLine() - shell.getHeight() + 1 == 0) {
      topBottomIndicator="String_Node_Str";
    }
 else     if (lineBuffer.atEnd()) {
      topBottomIndicator="String_Node_Str";
    }
 else {
      topBottomIndicator="String_Node_Str";
    }
    String prompt=MOREPROMPT + "String_Node_Str" + lineBuffer.getCurrentLine()+ topBottomIndicator+ "String_Node_Str";
    String bottomLineReset=new Ansi().cursor(shell.getHeight(),0).toString();
    shell.print(bottomLineReset);
    shell.print(attr(47,30));
    shell.print(prompt);
    shell.print(pad(shell.getWidth() - prompt.length()));
    shell.print(attr(0));
    shell.print(bottomLineReset);
    shell.print(attr(0));
    shell.flushBuffer();
    int scanCode=shell.scan();
    shell.clearLine();
switch (scanCode) {
case 'e':
case 'E':
case 'j':
case 'J':
case 16:
      lineBuffer.rewindBuffer(shell.getHeight() - 1,lineBuffer.getCurrentLine() - 1);
    lineBuffer.setLineWidth(shell.getWidth());
  return -1;
case 'u':
case 'U':
lineBuffer.rewindBuffer(shell.getHeight() - 1,lineBuffer.getCurrentLine() - shell.getHeight());
lineBuffer.setLineWidth(shell.getWidth());
return -1;
case 'y':
case 'Y':
case 'k':
case 'K':
case 14:
case '\n':
lineBuffer.setLineWidth(shell.getWidth());
return -2;
case ' ':
lineBuffer.setLineWidth(shell.getWidth());
return -3;
case 'q':
case 'Q':
shell.clearLine();
shell.cursorLeft(prompt.length());
shell.flushBuffer();
return 0;
case '?':
backwards=true;
case '/':
shell.clearLine();
shell.cursorLeft(prompt.length());
prompt=backwards ? SEARCH_BACKWARDS_PROMPT : SEARCH_FORWARD_PROMPT;
String pattern;
if (lastPattern != null) {
prompt+="String_Node_Str" + lastPattern + "String_Node_Str";
}
out.print(ShellColor.BOLD,prompt);
shell.flushBuffer();
pattern=shell.promptAndSwallowCR().trim();
String searched;
shell.clearLine();
shell.cursorLeft(prompt.length() + pattern.length());
prompt+="String_Node_Str";
out.print(ShellColor.BOLD,prompt);
shell.flushBuffer();
String p;
if (pattern.equals("String_Node_Str") && (lastPattern.length() != 0)) {
p=searched=lineBuffer.toString();
}
 else {
if (lastPattern.length() != 0) {
lastPattern.delete(0,lastPattern.length() - 1);
}
lastPattern.append(pattern);
p=searched=pattern;
}
int result=lineBuffer.findPattern(p,backwards);
if (result == -1) {
shell.clearLine();
shell.cursorLeft(prompt.length());
shell.print(ShellColor.RED,PATTERN_NOT_FOUND + searched);
shell.flushBuffer();
shell.scan();
shell.clearLine();
shell.cursorLeft(PATTERN_NOT_FOUND.length() + searched.length());
shell.flushBuffer();
}
 else {
lineBuffer.rewindBuffer(shell.getHeight() - 1,result);
shell.clear();
shell.flushBuffer();
return -1;
}
break;
default :
shell.clearLine();
shell.cursorLeft(prompt.length());
out.print(ShellColor.RED,INVALID_COMMAND + ((char)scanCode));
shell.scan();
shell.clearLine();
shell.cursorLeft(INVALID_COMMAND.length() + 1);
}
}
 while (true);
}