Program: 187967
Project: 187967
Buggy source:
/** 
 * Get ANSI colour sequence to append to the output
 * @param palette        The current colour palette
 * @param oldBackground  The current background colour
 * @param oldForeground  The current foreground colour
 * @parma  oldFormat      The current text format
 * @param newBackground  The new background colour
 * @param newForeground  The new foreground colour
 * @parma  newFormat      The new text format
 */
protected String applyColour(Color[] palette,Color oldBackground,Color oldForeground,boolean[] oldFormat,Color newBackground,Color newForeground,boolean[] newFormat){
  StringBuilder rc=new StringBuilder();
  int colourindex1back=-1, colourindex2back=-1;
  int colourindex1fore=-1, colourindex2fore=-1;
  if ((oldBackground != null) && (newBackground == null))   rc.append("String_Node_Str");
 else   if ((oldBackground == null) || (oldBackground.equals(newBackground) == false)) {
    if ((this.fullcolour && this.tty) == false)     colourindex1back=matchColour(newBackground,palette,16,256,this.chroma);
    if (this.tty || this.fullcolour)     colourindex2back=(this.colourful ? matchColour(this.fullcolour ? newBackground : palette[colourindex1back],palette,0,8,this.chroma) : 7);
 else     colourindex2back=colourindex1back;
  }
  if ((oldForeground != null) && (newForeground == null))   rc.append("String_Node_Str");
 else   if ((oldForeground == null) || (oldForeground.equals(newForeground) == false)) {
    if ((this.fullcolour && this.tty) == false)     colourindex1fore=matchColour(newBackground,palette,16,256,this.chroma);
    if (this.tty || this.fullcolour)     colourindex2fore=(this.colourful ? matchColour(this.fullcolour ? newForeground : palette[colourindex1fore],palette,0,16,this.chroma) : 15);
 else     colourindex2fore=colourindex1fore;
    if (colourindex2fore == colourindex2back)     colourindex2fore|=8;
  }
  if (colourindex2back != -1)   if (this.tty) {
    Color colour=palette[colourindex1back];
    rc.append("String_Node_Str");
    rc.append("String_Node_Str".charAt(colourindex1back));
    rc.append("String_Node_Str".charAt(colour.getRed() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getRed() & 15));
    rc.append("String_Node_Str".charAt(colour.getGreen() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getGreen() & 15));
    rc.append("String_Node_Str".charAt(colour.getBlue() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getBlue() & 15));
    rc.append("String_Node_Str");
    rc.append(colourindex2back);
  }
 else   if (this.fullcolour) {
    Color colour=newBackground;
    rc.append("String_Node_Str");
    rc.append(colourindex2back);
    rc.append("String_Node_Str");
    rc.append("String_Node_Str".charAt(colour.getRed() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getRed() & 15));
    rc.append('/');
    rc.append("String_Node_Str".charAt(colour.getGreen() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getGreen() & 15));
    rc.append('/');
    rc.append("String_Node_Str".charAt(colour.getBlue() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getBlue() & 15));
    rc.append("String_Node_Str");
    rc.append(colourindex2back);
    palette[colourindex2back]=colour;
  }
 else   if (colourindex2back < 16) {
    rc.append("String_Node_Str");
    rc.append(colourindex2back);
  }
 else {
    rc.append("String_Node_Str");
    rc.append(colourindex2back);
  }
  if (colourindex2fore != -1)   if (this.tty) {
    Color colour=palette[colourindex1fore];
    rc.append("String_Node_Str");
    rc.append("String_Node_Str".charAt(colourindex1fore));
    rc.append("String_Node_Str".charAt(colour.getRed() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getRed() & 15));
    rc.append("String_Node_Str".charAt(colour.getGreen() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getGreen() & 15));
    rc.append("String_Node_Str".charAt(colour.getBlue() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getBlue() & 15));
    rc.append("String_Node_Str");
    rc.append(colourindex2fore);
  }
 else   if (this.fullcolour) {
    Color colour=newForeground;
    rc.append("String_Node_Str");
    rc.append(colourindex2fore);
    rc.append("String_Node_Str");
    rc.append("String_Node_Str".charAt(colour.getRed() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getRed() & 15));
    rc.append('/');
    rc.append("String_Node_Str".charAt(colour.getGreen() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getGreen() & 15));
    rc.append('/');
    rc.append("String_Node_Str".charAt(colour.getBlue() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getBlue() & 15));
    rc.append("String_Node_Str");
    rc.append(colourindex2fore);
    palette[colourindex2fore]=colour;
  }
 else   if (colourindex2back < 16) {
    rc.append("String_Node_Str");
    rc.append(colourindex2fore);
  }
 else {
    rc.append("String_Node_Str");
    rc.append(colourindex2fore);
  }
  if (this.tty && (colourindex2fore >= 0))   newFormat[0]=(colourindex2fore & 8) == 8;
  for (int i=0; i < 9; i++)   if (newFormat[i] ^ oldFormat[i])   if (newFormat[i]) {
    rc.append("String_Node_Str");
    rc.append(i);
  }
 else {
    rc.append("String_Node_Str");
    rc.append(i);
  }
  String _rc=rc.toString();
  if (_rc.isEmpty())   return "String_Node_Str";
  return "String_Node_Str" + _rc.substring(1) + "String_Node_Str";
}

Fixed version (ground truth):
/** 
 * Get ANSI colour sequence to append to the output
 * @param palette        The current colour palette
 * @param oldBackground  The current background colour
 * @param oldForeground  The current foreground colour
 * @parma  oldFormat      The current text format
 * @param newBackground  The new background colour
 * @param newForeground  The new foreground colour
 * @parma  newFormat      The new text format
 */
protected String applyColour(Color[] palette,Color oldBackground,Color oldForeground,boolean[] oldFormat,Color newBackground,Color newForeground,boolean[] newFormat){
  StringBuilder rc=new StringBuilder();
  int colourindex1back=-1, colourindex2back=-1;
  int colourindex1fore=-1, colourindex2fore=-1;
  if ((oldBackground != null) && (newBackground == null))   rc.append("String_Node_Str");
 else   if ((oldBackground == null) || (oldBackground.equals(newBackground) == false))   if (newBackground != null) {
    if ((this.fullcolour && this.tty) == false)     colourindex1back=matchColour(newBackground,palette,16,256,this.chroma);
    if (this.tty || this.fullcolour)     colourindex2back=(this.colourful ? matchColour(this.fullcolour ? newBackground : palette[colourindex1back],palette,0,8,this.chroma) : 7);
 else     colourindex2back=colourindex1back;
  }
  if ((oldForeground != null) && (newForeground == null))   rc.append("String_Node_Str");
 else   if ((oldForeground == null) || (oldForeground.equals(newForeground) == false))   if (newForeground != null) {
    if ((this.fullcolour && this.tty) == false)     colourindex1fore=matchColour(newBackground,palette,16,256,this.chroma);
    if (this.tty || this.fullcolour)     colourindex2fore=(this.colourful ? matchColour(this.fullcolour ? newForeground : palette[colourindex1fore],palette,0,16,this.chroma) : 15);
 else     colourindex2fore=colourindex1fore;
    if (colourindex2fore == colourindex2back)     colourindex2fore|=8;
  }
  if (colourindex2back != -1)   if (this.tty) {
    Color colour=palette[colourindex1back];
    rc.append("String_Node_Str");
    rc.append("String_Node_Str".charAt(colourindex1back));
    rc.append("String_Node_Str".charAt(colour.getRed() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getRed() & 15));
    rc.append("String_Node_Str".charAt(colour.getGreen() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getGreen() & 15));
    rc.append("String_Node_Str".charAt(colour.getBlue() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getBlue() & 15));
    rc.append("String_Node_Str");
    rc.append(colourindex2back);
  }
 else   if (this.fullcolour) {
    Color colour=newBackground;
    rc.append("String_Node_Str");
    rc.append(colourindex2back);
    rc.append("String_Node_Str");
    rc.append("String_Node_Str".charAt(colour.getRed() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getRed() & 15));
    rc.append('/');
    rc.append("String_Node_Str".charAt(colour.getGreen() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getGreen() & 15));
    rc.append('/');
    rc.append("String_Node_Str".charAt(colour.getBlue() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getBlue() & 15));
    rc.append("String_Node_Str");
    rc.append(colourindex2back);
    palette[colourindex2back]=colour;
  }
 else   if (colourindex2back < 16) {
    rc.append("String_Node_Str");
    rc.append(colourindex2back);
  }
 else {
    rc.append("String_Node_Str");
    rc.append(colourindex2back);
  }
  if (colourindex2fore != -1)   if (this.tty) {
    Color colour=palette[colourindex1fore];
    rc.append("String_Node_Str");
    rc.append("String_Node_Str".charAt(colourindex1fore));
    rc.append("String_Node_Str".charAt(colour.getRed() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getRed() & 15));
    rc.append("String_Node_Str".charAt(colour.getGreen() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getGreen() & 15));
    rc.append("String_Node_Str".charAt(colour.getBlue() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getBlue() & 15));
    rc.append("String_Node_Str");
    rc.append(colourindex2fore);
  }
 else   if (this.fullcolour) {
    Color colour=newForeground;
    rc.append("String_Node_Str");
    rc.append(colourindex2fore);
    rc.append("String_Node_Str");
    rc.append("String_Node_Str".charAt(colour.getRed() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getRed() & 15));
    rc.append('/');
    rc.append("String_Node_Str".charAt(colour.getGreen() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getGreen() & 15));
    rc.append('/');
    rc.append("String_Node_Str".charAt(colour.getBlue() >>> 4));
    rc.append("String_Node_Str".charAt(colour.getBlue() & 15));
    rc.append("String_Node_Str");
    rc.append(colourindex2fore);
    palette[colourindex2fore]=colour;
  }
 else   if (colourindex2back < 16) {
    rc.append("String_Node_Str");
    rc.append(colourindex2fore);
  }
 else {
    rc.append("String_Node_Str");
    rc.append(colourindex2fore);
  }
  if (this.tty && (colourindex2fore >= 0))   newFormat[0]=(colourindex2fore & 8) == 8;
  for (int i=0; i < 9; i++)   if (newFormat[i] ^ oldFormat[i])   if (newFormat[i]) {
    rc.append("String_Node_Str");
    rc.append(i);
  }
 else {
    rc.append("String_Node_Str");
    rc.append(i);
  }
  String _rc=rc.toString();
  if (_rc.isEmpty())   return "String_Node_Str";
  return "String_Node_Str" + _rc.substring(1) + "String_Node_Str";
}