Program: 34371
Project: 34371
Buggy source:
boolean computeIntroduceMethod(TreePathHandle h,CompilationInfo info,TreePath treePath,Tree tree){
  TreePath block=treePath;
  TreePath method=findMethod(block);
  if (method == null) {
    TreePath parentPath=treePath.getParentPath();
    if (parentPath == null) {
      return false;
    }
    method=parentPath;
  }
  CompilationUnitTree compilationUnit=info.getCompilationUnit();
  SourcePositions sourcePositions=info.getTrees().getSourcePositions();
  long endPosition=sourcePositions.getEndPosition(compilationUnit,method.getLeaf());
  if (TreeUtilities.CLASS_TREE_KINDS.contains(method.getLeaf().getKind())) {
    this.classGeneratePosition=endPosition - 1;
  }
 else {
    this.classGeneratePosition=endPosition + 1;
  }
  List<? extends StatementTree> blockStatements=getStatements(block);
  StatementTree lastStatement=blockStatements.isEmpty() ? null : blockStatements.get(blockStatements.size() - 1);
  ScanLocalVars scanner=new ScanLocalVars(info,lastStatement);
  scanner.scan(block,null);
  Set<TypeMirror> exceptions=new HashSet<>();
  String returnType=scanner.getReturnType();
  if (returnType == null || !scanner.hasReturns()) {
    TypeMirror type=scanner.getReturnTypeMirror();
    if (type == null) {
      Element lastStatementElement;
      if (lastStatement != null && (lastStatementElement=getElement(info,new TreePath(treePath,lastStatement))) != null) {
        type=lastStatementElement.asType();
        if (TypeKind.EXECUTABLE.equals(type.getKind())) {
          ExecutableType eType=(ExecutableType)type;
          type=eType.getReturnType();
          long lsEnd=sourcePositions.getEndPosition(compilationUnit,lastStatement);
          if (lsEnd < 0) {
            lsEnd=this.snippetCode.length() - 1;
          }
 else {
            lsEnd-=codeOffset;
          }
          if (';' != this.snippetCode.charAt((int)lsEnd)) {
            this.snippetCode=new StringBuilder(this.snippetCode).insert((int)lsEnd + 1,"String_Node_Str").toString();
          }
        }
      }
    }
    if (type != null && !TypeKind.VOID.equals(type.getKind())) {
      returnType=type.toString();
      long lsBegin=sourcePositions.getStartPosition(compilationUnit,lastStatement);
      lsBegin-=codeOffset;
      this.snippetCode=new StringBuilder(this.snippetCode).insert((int)lsBegin,"String_Node_Str").toString();
    }
    if (returnType == null) {
      returnType=info.getTypes().getNoType(TypeKind.VOID).toString();
    }
  }
  for (  StatementTree s : blockStatements) {
    TreePath path=new TreePath(treePath,s);
    exceptions.addAll(info.getTreeUtilities().getUncaughtExceptions(path));
  }
  Set<VariableElement> referencedVariables=scanner.getReferencedVariables();
  StringBuilder declaration=new StringBuilder(returnType);
  declaration.append("String_Node_Str");
  boolean isFirst=true;
  for (  VariableElement var : referencedVariables) {
    if (!isFirst) {
      declaration.append("String_Node_Str");
    }
    declaration.append(var.asType().toString());
    declaration.append("String_Node_Str");
    declaration.append(var.getSimpleName().toString());
    isFirst=false;
  }
  declaration.append("String_Node_Str");
  if (!exceptions.isEmpty()) {
    declaration.append("String_Node_Str");
    isFirst=true;
    for (    TypeMirror exc : exceptions) {
      if (!isFirst) {
        declaration.append("String_Node_Str");
      }
      declaration.append(exc.toString());
      isFirst=false;
    }
  }
  declaration.append("String_Node_Str");
  declaration.append(snippetCode);
  declaration.append("String_Node_Str");
  this.methodBodyCode=declaration.toString();
  StringBuilder methodInvode=new StringBuilder("String_Node_Str");
  isFirst=true;
  for (  VariableElement var : referencedVariables) {
    if (!isFirst) {
      methodInvode.append("String_Node_Str");
    }
    methodInvode.append(var.getSimpleName().toString());
    isFirst=false;
  }
  methodInvode.append("String_Node_Str");
  this.methodInvokeCode=methodInvode.toString();
  return true;
}

Fixed version (ground truth):
boolean computeIntroduceMethod(TreePathHandle h,CompilationInfo info,TreePath treePath,Tree tree){
  TreePath block=treePath;
  TreePath method=findMethod(block);
  if (method == null) {
    TreePath parentPath=treePath.getParentPath();
    if (parentPath == null) {
      return false;
    }
    method=parentPath;
  }
  CompilationUnitTree compilationUnit=info.getCompilationUnit();
  SourcePositions sourcePositions=info.getTrees().getSourcePositions();
  long endPosition=sourcePositions.getEndPosition(compilationUnit,method.getLeaf());
  if (TreeUtilities.CLASS_TREE_KINDS.contains(method.getLeaf().getKind())) {
    this.classGeneratePosition=endPosition - 1;
  }
 else {
    this.classGeneratePosition=endPosition + 1;
  }
  List<? extends StatementTree> blockStatements=getStatements(block);
  StatementTree lastStatement=blockStatements.isEmpty() ? null : blockStatements.get(blockStatements.size() - 1);
  ScanLocalVars scanner=new ScanLocalVars(info,lastStatement);
  scanner.scan(block,null);
  Set<TypeMirror> exceptions=new HashSet<>();
  String returnType=scanner.getReturnType();
  if (returnType == null || !scanner.hasReturns()) {
    TypeMirror type=scanner.getReturnTypeMirror();
    if (type == null) {
      Element lastStatementElement;
      if (lastStatement != null && (lastStatementElement=getElement(info,new TreePath(treePath,lastStatement))) != null) {
        type=lastStatementElement.asType();
        if (TypeKind.EXECUTABLE.equals(type.getKind())) {
          ExecutableType eType=(ExecutableType)type;
          type=eType.getReturnType();
          long lsEnd=sourcePositions.getEndPosition(compilationUnit,lastStatement);
          if (lsEnd < 0) {
            lsEnd=this.snippetCode.length() - 1;
          }
 else {
            lsEnd-=codeOffset;
          }
          if (';' != this.snippetCode.charAt((int)lsEnd)) {
            this.snippetCode=new StringBuilder(this.snippetCode).insert((int)lsEnd + 1,"String_Node_Str").toString();
          }
        }
      }
    }
    if (type != null && !TypeKind.VOID.equals(type.getKind())) {
      returnType=type.toString();
      long lsBegin=sourcePositions.getStartPosition(compilationUnit,lastStatement);
      lsBegin-=codeOffset;
      this.snippetCode=new StringBuilder(this.snippetCode).insert((int)lsBegin,"String_Node_Str").append(';').toString();
    }
    if (returnType == null) {
      returnType=info.getTypes().getNoType(TypeKind.VOID).toString();
    }
  }
  for (  StatementTree s : blockStatements) {
    TreePath path=new TreePath(treePath,s);
    exceptions.addAll(info.getTreeUtilities().getUncaughtExceptions(path));
  }
  Set<VariableElement> referencedVariables=scanner.getReferencedVariables();
  StringBuilder declaration=new StringBuilder(returnType);
  declaration.append("String_Node_Str");
  boolean isFirst=true;
  for (  VariableElement var : referencedVariables) {
    if (!isFirst) {
      declaration.append("String_Node_Str");
    }
    declaration.append(var.asType().toString());
    declaration.append("String_Node_Str");
    declaration.append(var.getSimpleName().toString());
    isFirst=false;
  }
  declaration.append("String_Node_Str");
  if (!exceptions.isEmpty()) {
    declaration.append("String_Node_Str");
    isFirst=true;
    for (    TypeMirror exc : exceptions) {
      if (!isFirst) {
        declaration.append("String_Node_Str");
      }
      declaration.append(exc.toString());
      isFirst=false;
    }
  }
  declaration.append("String_Node_Str");
  declaration.append(snippetCode);
  declaration.append("String_Node_Str");
  this.methodBodyCode=declaration.toString();
  StringBuilder methodInvode=new StringBuilder("String_Node_Str");
  isFirst=true;
  for (  VariableElement var : referencedVariables) {
    if (!isFirst) {
      methodInvode.append("String_Node_Str");
    }
    methodInvode.append(var.getSimpleName().toString());
    isFirst=false;
  }
  methodInvode.append("String_Node_Str");
  this.methodInvokeCode=methodInvode.toString();
  return true;
}