Program: 15423
Project: 15423
Buggy source:
private static void clean(final IntArrayLengthPair input,final IntArrayLengthPair output){
  final boolean[] toRevert=new boolean[input.pos];
  final boolean[] toDelete=new boolean[input.pos];
  int lastUnderscore=-1, lastUnderscoreDouble=-1;
  int lastAsterisk=-1, lastAsteriskDouble=-1;
  int lastTildeDouble=-1;
  int lastBracketSquareOpen=-1;
  for (int i=0; i < input.pos; i++) {
    final int c=input.data[i];
switch (c) {
case TOKEN_UNDERSCORE:
      lastUnderscore=lastUnderscore < 0 ? i : -1;
    break;
case TOKEN_UNDERSCORE_DOUBLE:
  if (lastUnderscoreDouble < 0) {
    lastUnderscoreDouble=i;
  }
 else {
    if (lastUnderscoreDouble == i - 1) {
      toRevert[lastUnderscoreDouble]=true;
      toRevert[i]=true;
    }
    lastUnderscoreDouble=-1;
  }
break;
case TOKEN_ASTERISK:
lastAsterisk=lastAsterisk < 0 ? i : -1;
break;
case TOKEN_ASTERISK_DOUBLE:
if (lastAsteriskDouble < 0) {
lastAsteriskDouble=i;
}
 else {
if (lastAsteriskDouble == i - 1) {
toRevert[lastAsteriskDouble]=true;
toRevert[i]=true;
}
lastAsteriskDouble=-1;
}
break;
case TOKEN_TILDE_DOUBLE:
if (lastTildeDouble < 0) {
lastTildeDouble=i;
}
 else {
if (lastTildeDouble == i - 1) {
toRevert[lastTildeDouble]=true;
toRevert[i]=true;
}
lastTildeDouble=-1;
}
break;
case TOKEN_GRAVE:
final int openingGrave=i;
final int closingGrave=indexOf(input.data,TOKEN_GRAVE,i + 1,input.pos);
if (closingGrave < 0) {
toRevert[i]=true;
}
 else {
for (int j=openingGrave + 1; j < closingGrave; j++) {
if (input.data[j] < 0) toRevert[j]=true;
}
i=closingGrave;
}
break;
case TOKEN_BRACKET_SQUARE_OPEN:
if (lastBracketSquareOpen < 0) {
lastBracketSquareOpen=i;
}
 else {
toRevert[lastBracketSquareOpen]=true;
lastBracketSquareOpen=i;
}
break;
case TOKEN_BRACKET_SQUARE_CLOSE:
if (lastBracketSquareOpen < 0) {
toRevert[i]=true;
}
 else {
final int lastBracketSquareClose=i;
final int parenOpenPos=indexOf(input.data,TOKEN_PAREN_OPEN,lastBracketSquareClose + 1,input.pos);
boolean linkParseSuccess=false;
if (parenOpenPos >= 0) {
if (isSpaces(input.data,lastBracketSquareClose + 1,parenOpenPos)) {
final int parenClosePos=findParenClosePos(input,parenOpenPos + 1);
if (parenClosePos >= 0) {
linkParseSuccess=true;
for (int j=lastBracketSquareClose + 1; j < parenOpenPos; j++) {
toDelete[j]=true;
}
for (int j=parenOpenPos + 1; j < parenClosePos; j++) {
if (input.data[j] < 0) {
toRevert[j]=true;
}
 else if (input.data[j] == ' ' && input.data[j - 1] == ' ') {
toDelete[j]=true;
}
}
for (int j=parenOpenPos + 1; input.data[j] == ' '; j++) {
toDelete[j]=true;
}
for (int j=parenClosePos - 1; input.data[j] == ' '; j--) {
toDelete[j]=true;
}
i=parenClosePos;
}
}
}
if (!linkParseSuccess) {
toRevert[lastBracketSquareOpen]=true;
toRevert[lastBracketSquareClose]=true;
i=lastBracketSquareClose;
}
}
lastBracketSquareOpen=-1;
break;
case TOKEN_PAREN_OPEN:
case TOKEN_PAREN_CLOSE:
case TOKEN_UNICODE_CLOSE:
toRevert[i]=true;
break;
case TOKEN_UNICODE_OPEN:
final int openingUnicode=i;
final int closingUnicode=indexOf(input.data,TOKEN_UNICODE_CLOSE,i + 1,Math.min(input.pos,i + 8));
if (closingUnicode < 0 || !isDigits(input.data,openingUnicode + 1,closingUnicode)) {
toRevert[i]=true;
}
 else {
final int codePoint=getDecimal(input.data,openingUnicode + 1,closingUnicode);
if (unicodeWhitespace.contains(codePoint)) {
input.data[openingUnicode]=' ';
}
 else {
input.data[openingUnicode]=codePoint;
}
for (int j=openingUnicode + 1; j <= closingUnicode; j++) {
toDelete[j]=true;
}
i=closingUnicode;
}
break;
case TOKEN_CARET:
if (input.pos <= i + 1 || input.data[i + 1] == ' ') {
toRevert[i]=true;
}
break;
case ' ':
if (i < 1 || input.data[i - 1] == ' ') {
toDelete[i]=true;
}
break;
}
}
if (lastUnderscore >= 0) toRevert[lastUnderscore]=true;
if (lastUnderscoreDouble >= 0) toRevert[lastUnderscoreDouble]=true;
if (lastAsterisk >= 0) toRevert[lastAsterisk]=true;
if (lastAsteriskDouble >= 0) toRevert[lastAsteriskDouble]=true;
if (lastTildeDouble >= 0) toRevert[lastTildeDouble]=true;
if (lastBracketSquareOpen >= 0) toRevert[lastBracketSquareOpen]=true;
for (int j=input.pos - 1; j >= 0 && input.data[j] == ' '; j--) {
toDelete[j]=true;
}
output.clear();
for (int i=0; i < input.pos; i++) {
if (toDelete[i]) continue;
if (toRevert[i]) {
final char[] revertTo=reverseLookup[20 + input.data[i]];
output.append(revertTo);
}
 else {
output.data[output.pos++]=input.data[i];
}
}
}

Fixed version (ground truth):
private static void clean(final IntArrayLengthPair input,final IntArrayLengthPair output){
  final boolean[] toRevert=new boolean[input.pos];
  final boolean[] toDelete=new boolean[input.pos];
  int openingUnderscore=-1, openingUnderscoreDouble=-1;
  int openingAsterisk=-1, openingAsteriskDouble=-1;
  int openingTildeDouble=-1;
  int lastBracketSquareOpen=-1;
  for (int i=0; i < input.pos; i++) {
    final int c=input.data[i];
    final boolean beforeASpace=i + 1 < input.pos && input.data[i + 1] == ' ';
    final boolean afterASpace=i > 0 && input.data[i - 1] == ' ';
switch (c) {
case TOKEN_UNDERSCORE:
      if (openingUnderscore < 0) {
        if (beforeASpace) {
          toRevert[i]=true;
        }
 else {
          openingUnderscore=i;
        }
      }
 else {
        if (afterASpace) {
          toRevert[i]=true;
        }
 else {
          openingUnderscore=-1;
        }
      }
    break;
case TOKEN_UNDERSCORE_DOUBLE:
  if (i != 0 && openingUnderscoreDouble == i - 1) {
    toRevert[openingUnderscoreDouble]=true;
    toRevert[i]=true;
    openingUnderscoreDouble=-1;
  }
 else {
    if (openingUnderscoreDouble < 0) {
      if (beforeASpace) {
        toRevert[i]=true;
      }
 else {
        openingUnderscoreDouble=i;
      }
    }
 else {
      if (afterASpace) {
        toRevert[i]=true;
      }
 else {
        openingUnderscoreDouble=-1;
      }
    }
  }
break;
case TOKEN_ASTERISK:
if (openingAsterisk < 0) {
if (beforeASpace) {
  toRevert[i]=true;
}
 else {
  openingAsterisk=i;
}
}
 else {
if (afterASpace) {
  toRevert[i]=true;
}
 else {
  openingAsterisk=-1;
}
}
break;
case TOKEN_ASTERISK_DOUBLE:
if (i != 0 && openingAsteriskDouble == i - 1) {
toRevert[openingAsteriskDouble]=true;
toRevert[i]=true;
openingAsteriskDouble=-1;
}
 else {
if (openingAsteriskDouble < 0) {
if (beforeASpace) {
toRevert[i]=true;
}
 else {
openingAsteriskDouble=i;
}
}
 else {
if (afterASpace) {
toRevert[i]=true;
}
 else {
openingAsteriskDouble=-1;
}
}
}
break;
case TOKEN_TILDE_DOUBLE:
if (i != 0 && openingTildeDouble == i - 1) {
toRevert[openingTildeDouble]=true;
toRevert[i]=true;
openingTildeDouble=-1;
}
 else {
if (openingTildeDouble < 0) {
if (beforeASpace) {
toRevert[i]=true;
}
 else {
openingTildeDouble=i;
}
}
 else {
if (afterASpace) {
toRevert[i]=true;
}
 else {
openingTildeDouble=-1;
}
}
}
break;
case TOKEN_GRAVE:
final int openingGrave=i;
final int closingGrave=indexOf(input.data,TOKEN_GRAVE,i + 1,input.pos);
if (closingGrave < 0) {
toRevert[i]=true;
}
 else {
for (int j=openingGrave + 1; j < closingGrave; j++) {
if (input.data[j] < 0) toRevert[j]=true;
}
i=closingGrave;
}
break;
case TOKEN_BRACKET_SQUARE_OPEN:
if (lastBracketSquareOpen < 0) {
lastBracketSquareOpen=i;
}
 else {
toRevert[lastBracketSquareOpen]=true;
lastBracketSquareOpen=i;
}
break;
case TOKEN_BRACKET_SQUARE_CLOSE:
if (lastBracketSquareOpen < 0) {
toRevert[i]=true;
}
 else {
final int lastBracketSquareClose=i;
final int parenOpenPos=indexOf(input.data,TOKEN_PAREN_OPEN,lastBracketSquareClose + 1,input.pos);
boolean linkParseSuccess=false;
if (parenOpenPos >= 0) {
if (isSpaces(input.data,lastBracketSquareClose + 1,parenOpenPos)) {
final int parenClosePos=findParenClosePos(input,parenOpenPos + 1);
if (parenClosePos >= 0) {
linkParseSuccess=true;
for (int j=lastBracketSquareClose + 1; j < parenOpenPos; j++) {
toDelete[j]=true;
}
for (int j=parenOpenPos + 1; j < parenClosePos; j++) {
if (input.data[j] < 0) {
toRevert[j]=true;
}
 else if (input.data[j] == ' ' && input.data[j - 1] == ' ') {
toDelete[j]=true;
}
}
for (int j=parenOpenPos + 1; input.data[j] == ' '; j++) {
toDelete[j]=true;
}
for (int j=parenClosePos - 1; input.data[j] == ' '; j--) {
toDelete[j]=true;
}
i=parenClosePos;
}
}
}
if (!linkParseSuccess) {
toRevert[lastBracketSquareOpen]=true;
toRevert[lastBracketSquareClose]=true;
i=lastBracketSquareClose;
}
}
lastBracketSquareOpen=-1;
break;
case TOKEN_PAREN_OPEN:
case TOKEN_PAREN_CLOSE:
case TOKEN_UNICODE_CLOSE:
toRevert[i]=true;
break;
case TOKEN_UNICODE_OPEN:
final int openingUnicode=i;
final int closingUnicode=indexOf(input.data,TOKEN_UNICODE_CLOSE,i + 1,Math.min(input.pos,i + 8));
if (closingUnicode < 0 || !isDigits(input.data,openingUnicode + 1,closingUnicode)) {
toRevert[i]=true;
}
 else {
final int codePoint=getDecimal(input.data,openingUnicode + 1,closingUnicode);
if (unicodeWhitespace.contains(codePoint)) {
input.data[openingUnicode]=' ';
}
 else {
input.data[openingUnicode]=codePoint;
}
for (int j=openingUnicode + 1; j <= closingUnicode; j++) {
toDelete[j]=true;
}
i=closingUnicode;
}
break;
case TOKEN_CARET:
if (input.pos <= i + 1 || input.data[i + 1] == ' ') {
toRevert[i]=true;
}
break;
case ' ':
if (i < 1 || input.data[i - 1] == ' ') {
toDelete[i]=true;
}
break;
}
}
if (openingUnderscore >= 0) toRevert[openingUnderscore]=true;
if (openingUnderscoreDouble >= 0) toRevert[openingUnderscoreDouble]=true;
if (openingAsterisk >= 0) toRevert[openingAsterisk]=true;
if (openingAsteriskDouble >= 0) toRevert[openingAsteriskDouble]=true;
if (openingTildeDouble >= 0) toRevert[openingTildeDouble]=true;
if (lastBracketSquareOpen >= 0) toRevert[lastBracketSquareOpen]=true;
for (int j=input.pos - 1; j >= 0 && input.data[j] == ' '; j--) {
toDelete[j]=true;
}
output.clear();
for (int i=0; i < input.pos; i++) {
if (toDelete[i]) continue;
if (toRevert[i]) {
final char[] revertTo=reverseLookup[20 + input.data[i]];
output.append(revertTo);
}
 else {
output.data[output.pos++]=input.data[i];
}
}
}