Program: 12058
Project: 12058
Buggy source:
/** 
 * Get the information on the test methods corresponded the developing public methods.
 * @param javaFile
 * @return the information on the test methods
 * @throws Exception
 */
public static ClassInfo getTestClassInfoFromTargetClass(IFile javaFile) throws Exception {
  IPreferenceStore store=Activator.getDefault().getPreferenceStore();
  ClassInfo classInfo=new ClassInfo();
  List<MethodInfo> testMethods=new ArrayList<MethodInfo>();
  boolean enabled=store.getBoolean(Preference.TestMethodGen.ENABLE);
  if (!enabled) {
    return classInfo;
  }
  boolean enabledArgs=store.getBoolean(Preference.TestMethodGen.ARGS);
  boolean enabledReturn=store.getBoolean(Preference.TestMethodGen.RETURN);
  boolean enabledNotBlankMethods=store.getBoolean(Preference.TestMethodGen.METHOD_SAMPLE_IMPL);
  boolean enableExcludesAccessors=store.getBoolean(Preference.TestMethodGen.EXLCUDES_ACCESSORS);
  boolean enabledSupportJMock2=MockGenUtil.isUsingJMock2(store);
  boolean enabledSupportEasyMock=MockGenUtil.isUsingEasyMock(store);
  String delimiter=store.getString(Preference.TestMethodGen.DELIMITER);
  String argsPrefix=store.getString(Preference.TestMethodGen.ARGS_PREFIX);
  String argsDelimiter=store.getString(Preference.TestMethodGen.ARGS_DELIMITER);
  String returnPrefix=store.getString(Preference.TestMethodGen.RETURN_PREFIX);
  String returnDelimiter=store.getString(Preference.TestMethodGen.RETURN_DELIMITER);
  InputStream is=null;
  InputStreamReader isr=null;
  BufferedReader br=null;
  try {
    String encoding=FileResourceUtil.detectEncoding(javaFile);
    is=javaFile.getContents();
    isr=new InputStreamReader(is,encoding);
    br=new BufferedReader(isr);
    StringBuilder tmpsb=new StringBuilder();
    String line=null;
    while ((line=br.readLine()) != null) {
      tmpsb.append(trimLineComments(line) + "String_Node_Str");
    }
    String targetClassSourceStr=trimInnerClassMethods(trimAllComments(tmpsb.toString()));
    if (enabledNotBlankMethods) {
      if (testMethods.size() <= 0 || testMethods.get(0) == null)       testMethods.add(new MethodInfo());
      String[] importStartLines=targetClassSourceStr.split("String_Node_Str");
      for (      String importStartLine : importStartLines) {
        if (!importStartLine.matches("String_Node_Str")) {
          String importedPackage=importStartLine.split("String_Node_Str")[0];
          classInfo.importList.add(importedPackage);
        }
      }
      if (enabledSupportJMock2) {
        classInfo.importList.add("String_Node_Str");
        classInfo.importList.add("String_Node_Str");
        classInfo.importList.add("String_Node_Str");
      }
      if (enabledSupportEasyMock) {
        classInfo.importList.add("String_Node_Str");
        classInfo.importList.add("String_Node_Str");
      }
    }
    String[] targets=targetClassSourceStr.split("String_Node_Str");
    for (    String target : targets) {
      target=target.replaceAll("String_Node_Str" + STR.COMMA,STR.COMMA).replaceAll(STR.COMMA + "String_Node_Str",STR.COMMA).replaceAll("String_Node_Str","String_Node_Str").replaceAll("String_Node_Str","String_Node_Str");
      if (target.matches(RXP_SEARCH_METHOD)) {
        Matcher matcher=PAT_SEARCH_GROUP_METHOD.matcher(target);
        if (matcher.find()) {
          MethodInfo each=new MethodInfo();
          if (enabledNotBlankMethods || enabledReturn) {
            String returnTypeFull=getType(matcher.group(1));
            Matcher toGenericsMatcher=Pattern.compile(RXP_GENERICS_PART_GROUP).matcher(returnTypeFull);
            while (toGenericsMatcher.find()) {
              String[] generics=toGenericsMatcher.group().replaceAll("String_Node_Str",STR.EMPTY).replaceAll("String_Node_Str",STR.EMPTY).split("String_Node_Str");
              for (              String generic : generics) {
                generic=getClassInSourceCode(generic,STR.EMPTY,new ArrayList<String>());
                each.returnType.generics.add(generic);
              }
            }
            each.returnType.name=returnTypeFull.replace(RXP_GENERICS_PART,STR.EMPTY);
            each.returnType.nameInMethodName=getTypeAvailableInMethodName(each.returnType.name);
          }
          each.methodName=matcher.group(2);
          String args=matcher.group(3);
          String[] tmpArr=args.split("String_Node_Str");
          int tmpArrLen=tmpArr.length;
          List<String> tmpArrList=new ArrayList<String>();
          String buf=STR.EMPTY;
          for (int i=0; i < tmpArrLen; i++) {
            String element=tmpArr[i].trim();
            if (element.matches("String_Node_Str")) {
              tmpArrList.add(element);
              continue;
            }
            if (element.matches("String_Node_Str")) {
              buf+=element;
              continue;
            }
            if (element.matches("String_Node_Str")) {
              String result=buf + STR.COMMA + element;
              tmpArrList.add(result);
              buf=STR.EMPTY;
              continue;
            }
            if (!buf.equals(STR.EMPTY)) {
              buf+=STR.COMMA + element;
              continue;
            }
            tmpArrList.add(element);
          }
          String[] argArr=tmpArrList.toArray(new String[0]);
          if (enabledNotBlankMethods || enabledArgs) {
            int argArrLen=argArr.length;
            for (int i=0; i < argArrLen; i++) {
              ArgType argType=new ArgType();
              String argTypeFull=argArr[i];
              Matcher toGenericsMatcher=Pattern.compile(RXP_GENERICS_PART_GROUP).matcher(argTypeFull);
              while (toGenericsMatcher.find()) {
                String[] generics=toGenericsMatcher.group().replaceAll("String_Node_Str",STR.EMPTY).replaceAll("String_Node_Str",STR.EMPTY).split("String_Node_Str");
                for (                String generic : generics) {
                  generic=getClassInSourceCode(generic,STR.EMPTY,new ArrayList<String>());
                  argType.generics.add(generic);
                }
              }
              String argTypeStr=argTypeFull.replaceAll(RXP_GENERICS_PART,STR.EMPTY);
              argType.name=getType(argTypeStr);
              argType.nameInMethodName=getTypeAvailableInMethodName(argTypeStr);
              each.argTypes.add(argType);
            }
          }
          if (enableExcludesAccessors) {
            String fieldName=null;
            String fieldType=null;
            if (each.methodName.matches("String_Node_Str")) {
              fieldName=each.methodName.substring(3);
              if (each.argTypes.size() > 0) {
                fieldType=each.argTypes.get(0).name;
              }
            }
 else             if (each.methodName.matches("String_Node_Str")) {
              fieldName=each.methodName.substring(3);
              fieldType=each.returnType.name;
            }
 else             if (each.methodName.matches("String_Node_Str")) {
              fieldName=each.methodName.substring(2);
              fieldType=each.returnType.name;
            }
            if (fieldName != null) {
              fieldName=fieldName.substring(0,1).toLowerCase() + fieldName.substring(1);
              fieldType=fieldType.replaceAll("String_Node_Str","String_Node_Str").replaceAll("String_Node_Str","String_Node_Str");
              String searchRegexp="String_Node_Str" + fieldType + "String_Node_Str"+ fieldName+ "String_Node_Str";
              if (targetClassSourceStr.matches(searchRegexp))               continue;
            }
          }
          each.testMethodName="String_Node_Str" + each.methodName;
          if (enabledArgs) {
            each.testMethodName+=delimiter + argsPrefix;
            if (each.argTypes.size() == 0)             each.testMethodName+=argsDelimiter;
            for (            ArgType argType : each.argTypes)             each.testMethodName+=argsDelimiter + argType.nameInMethodName;
          }
          if (enabledReturn)           each.testMethodName+=delimiter + returnPrefix + returnDelimiter+ each.returnType.nameInMethodName;
          if (target.matches(RXP_SEARCH_STATIC_METHOD))           each.isStatic=true;
          testMethods.add(each);
        }
      }
    }
  }
  finally {
    FileResourceUtil.close(br);
    FileResourceUtil.close(isr);
    FileResourceUtil.close(is);
  }
  classInfo.methods=testMethods;
  return classInfo;
}

Fixed version (ground truth):
/** 
 * Get the information on the test methods corresponded the developing public methods.
 * @param javaFile
 * @return the information on the test methods
 * @throws Exception
 */
public static ClassInfo getTestClassInfoFromTargetClass(IFile javaFile) throws Exception {
  IPreferenceStore store=Activator.getDefault().getPreferenceStore();
  ClassInfo classInfo=new ClassInfo();
  List<MethodInfo> testMethods=new ArrayList<MethodInfo>();
  boolean enabled=store.getBoolean(Preference.TestMethodGen.ENABLE);
  if (!enabled) {
    return classInfo;
  }
  boolean enabledArgs=store.getBoolean(Preference.TestMethodGen.ARGS);
  boolean enabledReturn=store.getBoolean(Preference.TestMethodGen.RETURN);
  boolean enabledNotBlankMethods=store.getBoolean(Preference.TestMethodGen.METHOD_SAMPLE_IMPL);
  boolean enableExcludesAccessors=store.getBoolean(Preference.TestMethodGen.EXLCUDES_ACCESSORS);
  boolean enabledSupportJMock2=MockGenUtil.isUsingJMock2(store);
  boolean enabledSupportEasyMock=MockGenUtil.isUsingEasyMock(store);
  String delimiter=store.getString(Preference.TestMethodGen.DELIMITER);
  String argsPrefix=store.getString(Preference.TestMethodGen.ARGS_PREFIX);
  String argsDelimiter=store.getString(Preference.TestMethodGen.ARGS_DELIMITER);
  String returnPrefix=store.getString(Preference.TestMethodGen.RETURN_PREFIX);
  String returnDelimiter=store.getString(Preference.TestMethodGen.RETURN_DELIMITER);
  InputStream is=null;
  InputStreamReader isr=null;
  BufferedReader br=null;
  try {
    String encoding=FileResourceUtil.detectEncoding(javaFile);
    is=javaFile.getContents();
    isr=new InputStreamReader(is,encoding);
    br=new BufferedReader(isr);
    StringBuilder tmpsb=new StringBuilder();
    String line=null;
    while ((line=br.readLine()) != null) {
      tmpsb.append(trimLineComments(line) + "String_Node_Str");
    }
    String targetClassSourceStr=trimInsideOfBraces(trimAllComments(tmpsb.toString()));
    if (enabledNotBlankMethods) {
      if (testMethods.size() <= 0 || testMethods.get(0) == null)       testMethods.add(new MethodInfo());
      String[] importStartLines=targetClassSourceStr.split("String_Node_Str");
      for (      String importStartLine : importStartLines) {
        if (!importStartLine.matches("String_Node_Str")) {
          String importedPackage=importStartLine.split("String_Node_Str")[0];
          classInfo.importList.add(importedPackage);
        }
      }
      if (enabledSupportJMock2) {
        classInfo.importList.add("String_Node_Str");
        classInfo.importList.add("String_Node_Str");
        classInfo.importList.add("String_Node_Str");
      }
      if (enabledSupportEasyMock) {
        classInfo.importList.add("String_Node_Str");
        classInfo.importList.add("String_Node_Str");
      }
    }
    String[] targets=targetClassSourceStr.split("String_Node_Str");
    for (    String target : targets) {
      target=target.replaceAll("String_Node_Str" + STR.COMMA,STR.COMMA).replaceAll(STR.COMMA + "String_Node_Str",STR.COMMA).replaceAll("String_Node_Str","String_Node_Str").replaceAll("String_Node_Str","String_Node_Str");
      if (target.matches(RXP_SEARCH_METHOD)) {
        Matcher matcher=PAT_SEARCH_GROUP_METHOD.matcher(target);
        if (matcher.find()) {
          MethodInfo each=new MethodInfo();
          if (enabledNotBlankMethods || enabledReturn) {
            String returnTypeFull=getType(matcher.group(1));
            Matcher toGenericsMatcher=Pattern.compile(RXP_GENERICS_PART_GROUP).matcher(returnTypeFull);
            while (toGenericsMatcher.find()) {
              String[] generics=toGenericsMatcher.group().replaceAll("String_Node_Str",STR.EMPTY).replaceAll("String_Node_Str",STR.EMPTY).split("String_Node_Str");
              for (              String generic : generics) {
                generic=getClassInSourceCode(generic,STR.EMPTY,new ArrayList<String>());
                each.returnType.generics.add(generic);
              }
            }
            each.returnType.name=returnTypeFull.replace(RXP_GENERICS_PART,STR.EMPTY);
            each.returnType.nameInMethodName=getTypeAvailableInMethodName(each.returnType.name);
          }
          each.methodName=matcher.group(2);
          String args=matcher.group(3);
          String[] tmpArr=args.split("String_Node_Str");
          int tmpArrLen=tmpArr.length;
          List<String> tmpArrList=new ArrayList<String>();
          String buf=STR.EMPTY;
          for (int i=0; i < tmpArrLen; i++) {
            String element=tmpArr[i].trim();
            if (element.matches("String_Node_Str")) {
              tmpArrList.add(element);
              continue;
            }
            if (element.matches("String_Node_Str")) {
              buf+=element;
              continue;
            }
            if (element.matches("String_Node_Str")) {
              String result=buf + STR.COMMA + element;
              tmpArrList.add(result);
              buf=STR.EMPTY;
              continue;
            }
            if (!buf.equals(STR.EMPTY)) {
              buf+=STR.COMMA + element;
              continue;
            }
            tmpArrList.add(element);
          }
          String[] argArr=tmpArrList.toArray(new String[0]);
          if (enabledNotBlankMethods || enabledArgs) {
            int argArrLen=argArr.length;
            for (int i=0; i < argArrLen; i++) {
              ArgType argType=new ArgType();
              String argTypeFull=argArr[i];
              Matcher toGenericsMatcher=Pattern.compile(RXP_GENERICS_PART_GROUP).matcher(argTypeFull);
              while (toGenericsMatcher.find()) {
                String[] generics=toGenericsMatcher.group().replaceAll("String_Node_Str",STR.EMPTY).replaceAll("String_Node_Str",STR.EMPTY).split("String_Node_Str");
                for (                String generic : generics) {
                  generic=getClassInSourceCode(generic,STR.EMPTY,new ArrayList<String>());
                  argType.generics.add(generic);
                }
              }
              String argTypeStr=argTypeFull.replaceAll(RXP_GENERICS_PART,STR.EMPTY);
              argType.name=getType(argTypeStr);
              argType.nameInMethodName=getTypeAvailableInMethodName(argTypeStr);
              each.argTypes.add(argType);
            }
          }
          if (enableExcludesAccessors) {
            String fieldName=null;
            String fieldType=null;
            if (each.methodName.matches("String_Node_Str")) {
              fieldName=each.methodName.substring(3);
              if (each.argTypes.size() > 0) {
                fieldType=each.argTypes.get(0).name;
              }
            }
 else             if (each.methodName.matches("String_Node_Str")) {
              fieldName=each.methodName.substring(3);
              fieldType=each.returnType.name;
            }
 else             if (each.methodName.matches("String_Node_Str")) {
              fieldName=each.methodName.substring(2);
              fieldType=each.returnType.name;
            }
            if (fieldName != null) {
              fieldName=fieldName.substring(0,1).toLowerCase() + fieldName.substring(1);
              fieldType=fieldType.replaceAll("String_Node_Str","String_Node_Str").replaceAll("String_Node_Str","String_Node_Str");
              String searchRegexp="String_Node_Str" + fieldType + "String_Node_Str"+ fieldName+ "String_Node_Str";
              if (targetClassSourceStr.matches(searchRegexp))               continue;
            }
          }
          each.testMethodName="String_Node_Str" + each.methodName;
          if (enabledArgs) {
            each.testMethodName+=delimiter + argsPrefix;
            if (each.argTypes.size() == 0)             each.testMethodName+=argsDelimiter;
            for (            ArgType argType : each.argTypes)             each.testMethodName+=argsDelimiter + argType.nameInMethodName;
          }
          if (enabledReturn)           each.testMethodName+=delimiter + returnPrefix + returnDelimiter+ each.returnType.nameInMethodName;
          if (target.matches(RXP_SEARCH_STATIC_METHOD))           each.isStatic=true;
          testMethods.add(each);
        }
      }
    }
  }
  finally {
    FileResourceUtil.close(br);
    FileResourceUtil.close(isr);
    FileResourceUtil.close(is);
  }
  classInfo.methods=testMethods;
  return classInfo;
}