Program: 185449
Project: 185449
Buggy source:
@Override protected String computeReplacementString(){
  if (fProposal.getCompletion() == null || fProposal.getCompletion().length == 0) {
    return "String_Node_Str";
  }
  char[] proposalName=fProposal.getName();
  boolean hasWhitespace=ProposalUtils.hasWhitespace(proposalName);
  if (fProposal.getKind() == CompletionProposal.METHOD_NAME_REFERENCE) {
    return String.valueOf(!hasWhitespace ? proposalName : CharOperation.concat('"',proposalName,'"'));
  }
  if (!hasWhitespace && (!hasParameters() || !hasArgumentList())) {
    String replacementString=super.computeReplacementString();
    if (replacementString.endsWith("String_Node_Str")) {
      replacementString=replacementString.substring(0,replacementString.length() - 1);
    }
    return replacementString;
  }
  StringBuffer buffer=new StringBuffer();
  fProposal.setName(!hasWhitespace ? proposalName : CharOperation.concat('"',proposalName,'"'));
  appendMethodNameReplacement(buffer);
  fProposal.setName(proposalName);
  if (!hasParameters()) {
    while (Character.isWhitespace(buffer.charAt(buffer.length() - 1))) {
      buffer.deleteCharAt(buffer.length() - 1);
    }
    if (fPreferences.isEnabled(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BETWEEN_EMPTY_PARENS_IN_METHOD_INVOCATION)) {
      buffer.append(SPACE);
    }
    buffer.append(RPAREN);
  }
 else   if (!fPreferences.isEnabled(PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES)) {
    if (fPreferences.bCommandChaining) {
      int i=buffer.lastIndexOf(LPAREN);
      while (Character.isWhitespace(buffer.charAt(i - 1))) {
        i-=1;
      }
      buffer.replace(i,buffer.length(),SPACE);
    }
 else     if (fPreferences.isEnabled(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_PAREN_IN_METHOD_INVOCATION)) {
      buffer.append(SPACE);
    }
    setContextInformationPosition(buffer.length());
    if (!fPreferences.bCommandChaining)     buffer.append(RPAREN);
  }
 else {
    int indexOfLastClosure=-1;
    char[][] namedParameterTypes=((GroovyCompletionProposal)fProposal).getNamedParameterTypeNames();
    char[][] regularParameterTypes=((GroovyCompletionProposal)fProposal).getRegularParameterTypeNames();
    if (fPreferences.bCommandChaining) {
      int i=buffer.lastIndexOf(LPAREN);
      while (Character.isWhitespace(buffer.charAt(i - 1))) {
        i-=1;
      }
      buffer.replace(i,buffer.length(),SPACE);
    }
 else     if (fPreferences.isEnabled(GroovyContentAssist.CLOSURE_NOPARENS)) {
      if (lastParamIsClosure(regularParameterTypes,CharOperation.NO_CHAR_CHAR)) {
        indexOfLastClosure=namedParameterTypes.length + regularParameterTypes.length - 1;
      }
      if (indexOfLastClosure == 0) {
        buffer.deleteCharAt(buffer.length() - 1);
        if (!fPreferences.isEnabled(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_METHOD_INVOCATION)) {
          buffer.append(SPACE);
        }
      }
    }
 else     if (fPreferences.isEnabled(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_PAREN_IN_METHOD_INVOCATION)) {
      buffer.append(SPACE);
    }
    setContextInformationPosition(buffer.length());
    char[][] namedParameterNames=((GroovyCompletionProposal)fProposal).getNamedParameterNames();
    char[][] regularParameterNames=((GroovyCompletionProposal)fProposal).getRegularParameterNames();
    int namedCount=namedParameterNames.length, totalCount=regularParameterNames.length + namedCount;
    computeReplacementProposals(namedParameterNames,regularParameterNames,indexOfLastClosure);
    for (int i=0; i < totalCount; i+=1) {
      @SuppressWarnings("String_Node_Str") char[] nextName, nextType;
      if (i < namedCount) {
        nextName=namedParameterNames[i];
        nextType=namedParameterTypes[i];
      }
 else {
        nextName=regularParameterNames[i - namedCount];
        nextType=regularParameterTypes[i - namedCount];
      }
      String nextValue=fProposals.get(i)[0].getDisplayString();
      if ((fPreferences.isEnabled(GroovyContentAssist.NAMED_ARGUMENTS) || i < namedCount) && i != indexOfLastClosure) {
        buffer.append(nextName);
        if (fPreferences.isEnabled(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_COLON_IN_LABELED_STATEMENT)) {
          buffer.append(SPACE);
        }
        buffer.append("String_Node_Str");
        if (fPreferences.isEnabled(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COLON_IN_LABELED_STATEMENT)) {
          buffer.append(SPACE);
        }
      }
      fPositions.get(i).setLength(nextValue.length());
      fPositions.get(i).setOffset(buffer.length());
      buffer.append(nextValue);
      if (i == (indexOfLastClosure - 1) || (i != indexOfLastClosure && i == (totalCount - 1) && !fPreferences.bCommandChaining)) {
        if (fPreferences.isEnabled(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_PAREN_IN_METHOD_INVOCATION)) {
          buffer.append(SPACE);
        }
        buffer.append(RPAREN);
        if (i == (indexOfLastClosure - 1) && (!fPreferences.isEnabled(GroovyContentAssist.CLOSURE_BRACKETS) || fPreferences.isEnabled(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_BLOCK))) {
          buffer.append(SPACE);
        }
      }
 else       if (i < (totalCount - 1)) {
        if (fPreferences.isEnabled(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_METHOD_INVOCATION_ARGUMENTS)) {
          buffer.append(SPACE);
        }
        buffer.append(COMMA);
        if (fPreferences.isEnabled(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_METHOD_INVOCATION_ARGUMENTS)) {
          buffer.append(SPACE);
        }
      }
    }
  }
  return buffer.toString();
}

Fixed version (ground truth):
@Override protected String computeReplacementString(){
  if (fProposal.getCompletion() == null || fProposal.getCompletion().length == 0) {
    setContextInformationPosition(1);
    return "String_Node_Str";
  }
  char[] proposalName=fProposal.getName();
  boolean hasWhitespace=ProposalUtils.hasWhitespace(proposalName);
  if (fProposal.getKind() == CompletionProposal.METHOD_NAME_REFERENCE) {
    return String.valueOf(!hasWhitespace ? proposalName : CharOperation.concat('"',proposalName,'"'));
  }
  if (!hasWhitespace && (!hasParameters() || !hasArgumentList())) {
    String replacementString=super.computeReplacementString();
    if (replacementString.endsWith("String_Node_Str")) {
      replacementString=replacementString.substring(0,replacementString.length() - 1);
    }
    return replacementString;
  }
  StringBuffer buffer=new StringBuffer();
  fProposal.setName(!hasWhitespace ? proposalName : CharOperation.concat('"',proposalName,'"'));
  appendMethodNameReplacement(buffer);
  fProposal.setName(proposalName);
  if (!hasParameters()) {
    while (Character.isWhitespace(buffer.charAt(buffer.length() - 1))) {
      buffer.deleteCharAt(buffer.length() - 1);
    }
    if (fPreferences.isEnabled(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BETWEEN_EMPTY_PARENS_IN_METHOD_INVOCATION)) {
      buffer.append(SPACE);
    }
    buffer.append(RPAREN);
  }
 else   if (!fPreferences.isEnabled(PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES)) {
    if (fPreferences.bCommandChaining) {
      int i=buffer.lastIndexOf(LPAREN);
      while (Character.isWhitespace(buffer.charAt(i - 1))) {
        i-=1;
      }
      buffer.replace(i,buffer.length(),SPACE);
    }
 else     if (fPreferences.isEnabled(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_PAREN_IN_METHOD_INVOCATION)) {
      buffer.append(SPACE);
    }
    setContextInformationPosition(buffer.length());
    if (!fPreferences.bCommandChaining)     buffer.append(RPAREN);
  }
 else {
    int indexOfLastClosure=-1;
    char[][] namedParameterTypes=((GroovyCompletionProposal)fProposal).getNamedParameterTypeNames();
    char[][] regularParameterTypes=((GroovyCompletionProposal)fProposal).getRegularParameterTypeNames();
    if (fPreferences.bCommandChaining) {
      int i=buffer.lastIndexOf(LPAREN);
      while (Character.isWhitespace(buffer.charAt(i - 1))) {
        i-=1;
      }
      buffer.replace(i,buffer.length(),SPACE);
    }
 else     if (fPreferences.isEnabled(GroovyContentAssist.CLOSURE_NOPARENS)) {
      if (lastParamIsClosure(regularParameterTypes,CharOperation.NO_CHAR_CHAR)) {
        indexOfLastClosure=namedParameterTypes.length + regularParameterTypes.length - 1;
      }
      if (indexOfLastClosure == 0) {
        buffer.deleteCharAt(buffer.length() - 1);
        if (!fPreferences.isEnabled(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_METHOD_INVOCATION)) {
          buffer.append(SPACE);
        }
      }
    }
 else     if (fPreferences.isEnabled(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_PAREN_IN_METHOD_INVOCATION)) {
      buffer.append(SPACE);
    }
    setContextInformationPosition(buffer.length());
    char[][] namedParameterNames=((GroovyCompletionProposal)fProposal).getNamedParameterNames();
    char[][] regularParameterNames=((GroovyCompletionProposal)fProposal).getRegularParameterNames();
    int namedCount=namedParameterNames.length, totalCount=regularParameterNames.length + namedCount;
    computeReplacementProposals(namedParameterNames,regularParameterNames,indexOfLastClosure);
    for (int i=0; i < totalCount; i+=1) {
      @SuppressWarnings("String_Node_Str") char[] nextName, nextType;
      if (i < namedCount) {
        nextName=namedParameterNames[i];
        nextType=namedParameterTypes[i];
      }
 else {
        nextName=regularParameterNames[i - namedCount];
        nextType=regularParameterTypes[i - namedCount];
      }
      String nextValue=fProposals.get(i)[0].getDisplayString();
      if ((fPreferences.isEnabled(GroovyContentAssist.NAMED_ARGUMENTS) || i < namedCount) && i != indexOfLastClosure) {
        buffer.append(nextName);
        if (fPreferences.isEnabled(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_COLON_IN_LABELED_STATEMENT)) {
          buffer.append(SPACE);
        }
        buffer.append("String_Node_Str");
        if (fPreferences.isEnabled(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COLON_IN_LABELED_STATEMENT)) {
          buffer.append(SPACE);
        }
      }
      fPositions.get(i).setLength(nextValue.length());
      fPositions.get(i).setOffset(buffer.length());
      buffer.append(nextValue);
      if (i == (indexOfLastClosure - 1) || (i != indexOfLastClosure && i == (totalCount - 1) && !fPreferences.bCommandChaining)) {
        if (fPreferences.isEnabled(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_PAREN_IN_METHOD_INVOCATION)) {
          buffer.append(SPACE);
        }
        buffer.append(RPAREN);
        if (i == (indexOfLastClosure - 1) && (!fPreferences.isEnabled(GroovyContentAssist.CLOSURE_BRACKETS) || fPreferences.isEnabled(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_BLOCK))) {
          buffer.append(SPACE);
        }
      }
 else       if (i < (totalCount - 1)) {
        if (fPreferences.isEnabled(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_METHOD_INVOCATION_ARGUMENTS)) {
          buffer.append(SPACE);
        }
        buffer.append(COMMA);
        if (fPreferences.isEnabled(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_METHOD_INVOCATION_ARGUMENTS)) {
          buffer.append(SPACE);
        }
      }
    }
  }
  return buffer.toString();
}