Program: 135885
Project: 135885
Buggy source:
/** 
 * The argument spec is the current tokenized specification, generated by the Tokenize method.  If that spec has a C-Syntax PlusCal algorithm, this method turns "(", ")", "{", and "}" tokens that are PlusCal delimiters (rather than parts of an expression) into the corresponding tokens that produce the appropriate TeX output.   A PlusCal "(" can follow the following: "macro" + IDENT "procedure" + an IDENT  "process" | "if" | "while" | "with" A PlusCal "{" other than the initial one can follow the following: a PlusCal "{" a PlusCal ")" "else" | "either" | "or" | "define" "variable[s]" [<expression> [, | ;]]^+  ";"   PCAL_LABEL This method also removes an extra gray bar that can appear after the algorithm when using the -shade and -noPcalShade options. The isTeX argument is true if this is called for tla2tex.TeX, in  which case the spec can start anywhere inside a PlusCal algorithm.
 * @param spec
 * @param isTeX  true for tla2tex.TeX, false for tla2tex.TLA
 */
public static void FixPlusCal(Token[][] spec,boolean isTeX){
  if (!hasPcal) {
    return;
  }
  if (Parameters.CommentShading && Parameters.NoPlusCalShading && (pcalEnd.line < spec.length)&& (pcalEnd.item < spec[pcalEnd.line].length)) {
    Token tok=pcalEnd.toToken(spec);
    if (tok.type == Token.COMMENT) {
      CommentToken ctok=(CommentToken)tok;
      if (ctok.string.trim().equals("String_Node_Str")) {
        int rsubtype=ctok.rsubtype;
        Token[] newline=new Token[spec[pcalEnd.line].length - 1];
        int j=0;
        for (int i=0; i < spec[pcalEnd.line].length; i++) {
          if (i != pcalEnd.item) {
            newline[j]=spec[pcalEnd.line][i];
            j++;
          }
        }
        if (rsubtype == CommentToken.NORMAL) {
          spec[pcalEnd.line]=newline;
        }
 else {
          if (rsubtype == CommentToken.BEGIN_OVERRUN) {
            Token next=spec[pcalEnd.line + 1][0];
            int nextLine=pcalEnd.line + 1;
            while ((next != null) && (next.type == CommentToken.COMMENT) && (((CommentToken)next).rsubtype == CommentToken.OVERRUN)&& (next.string.trim().equals("String_Node_Str"))) {
              nextLine++;
              if (spec[nextLine + 1].length > 0) {
                next=spec[nextLine][0];
              }
 else {
                next=null;
              }
            }
            if ((next != null) && (next.type == CommentToken.COMMENT) && (next.string.trim().equals("String_Node_Str"))&& (((CommentToken)next).rsubtype == CommentToken.END_OVERRUN)) {
              spec[pcalEnd.line]=newline;
              for (int i=pcalEnd.line + 1; i < nextLine; i++) {
                spec[i]=new Token[0];
              }
              newline=new Token[spec[nextLine].length - 1];
              System.arraycopy(spec[nextLine],1,newline,0,spec[nextLine].length - 1);
              spec[nextLine]=newline;
            }
          }
        }
      }
    }
  }
  if (!isCSyntax) {
    return;
  }
  Position pos=pcalStart;
  if (!isTeX) {
    while ((pos != null) && ((pos.toToken(spec).type != Token.BUILTIN) || (!pos.toToken(spec).string.equals("String_Node_Str")))) {
      pos=nextTokenPos(pos,spec);
    }
  }
  if (pos != null) {
    pos=ProcessPcalBrace(pos,spec,isTeX);
  }
  while (isTeX && (pos != null)) {
    pos=ProcessPcalBrace(pos,spec,isTeX);
  }
}

Fixed version (ground truth):
/** 
 * The argument spec is the current tokenized specification, generated by the Tokenize method.  If that spec has a C-Syntax PlusCal algorithm, this method turns "(", ")", "{", and "}" tokens that are PlusCal delimiters (rather than parts of an expression) into the corresponding tokens that produce the appropriate TeX output.   A PlusCal "(" can follow the following: "macro" + IDENT "procedure" + an IDENT  "process" | "if" | "while" | "with" A PlusCal "{" other than the initial one can follow the following: a PlusCal "{" a PlusCal ")" "else" | "either" | "or" | "define" "variable[s]" [<expression> [, | ;]]^+  ";"   PCAL_LABEL This method also removes an extra gray bar that can appear after the algorithm when using the -shade and -noPcalShade options. The isTeX argument is true if this is called for tla2tex.TeX, in  which case the spec can start anywhere inside a PlusCal algorithm.
 * @param spec
 * @param isTeX  true for tla2tex.TeX, false for tla2tex.TLA
 */
public static void FixPlusCal(Token[][] spec,boolean isTeX){
  if (!hasPcal) {
    return;
  }
  if (Parameters.CommentShading && Parameters.NoPlusCalShading && (pcalEnd.line < spec.length)&& (pcalEnd.item < spec[pcalEnd.line].length)) {
    Token tok=pcalEnd.toToken(spec);
    if (tok.type == Token.COMMENT) {
      CommentToken ctok=(CommentToken)tok;
      if (ctok.string.trim().equals("String_Node_Str")) {
        int rsubtype=ctok.rsubtype;
        Token[] newline=new Token[spec[pcalEnd.line].length - 1];
        int j=0;
        for (int i=0; i < spec[pcalEnd.line].length; i++) {
          if (i != pcalEnd.item) {
            newline[j]=spec[pcalEnd.line][i];
            j++;
          }
        }
        if (rsubtype == CommentToken.NORMAL) {
          spec[pcalEnd.line]=newline;
        }
 else {
          if (rsubtype == CommentToken.BEGIN_OVERRUN) {
            Token next=spec[pcalEnd.line + 1][0];
            int nextLine=pcalEnd.line + 1;
            while ((next != null) && (next.type == CommentToken.COMMENT) && (((CommentToken)next).rsubtype == CommentToken.OVERRUN)&& (next.string.trim().equals("String_Node_Str"))) {
              nextLine++;
              if (spec[nextLine + 1].length > 0) {
                next=spec[nextLine][0];
              }
 else {
                next=null;
              }
            }
            if ((next != null) && (next.type == CommentToken.COMMENT) && (next.string.trim().equals("String_Node_Str"))&& (((CommentToken)next).rsubtype == CommentToken.END_OVERRUN)) {
              spec[pcalEnd.line]=newline;
              for (int i=pcalEnd.line + 1; i < nextLine; i++) {
                spec[i]=new Token[0];
              }
              newline=new Token[spec[nextLine].length - 1];
              System.arraycopy(spec[nextLine],1,newline,0,spec[nextLine].length - 1);
              spec[nextLine]=newline;
            }
          }
        }
      }
    }
  }
  if (!isCSyntax) {
    return;
  }
  Position pos=pcalStart;
  boolean beginningOfAlgorithm=!isTeX;
  if (isTeX && pos != null) {
    String firstString=pos.toToken(spec).string;
    if (firstString.equals("String_Node_Str") || firstString.equals("String_Node_Str")) {
      beginningOfAlgorithm=true;
    }
  }
  if (beginningOfAlgorithm) {
    while ((pos != null) && ((pos.toToken(spec).type != Token.BUILTIN) || (!pos.toToken(spec).string.equals("String_Node_Str")))) {
      pos=nextTokenPos(pos,spec);
    }
  }
  if (pos != null) {
    pos=ProcessPcalBrace(pos,spec,isTeX);
  }
  while (isTeX && (pos != null)) {
    pos=ProcessPcalBrace(pos,spec,isTeX);
  }
}