Program: 17841
Project: 17841
Buggy source:
List<String> writeDocumentation(List<RestDocumentation> docs,Iterable<Pattern> excludePatterns,String scope) throws IOException, ClassNotFoundException, TemplateException {
  List<String> filesWritten=new ArrayList<String>();
  Map<String,RestDocumentation.RestApi> aggregatedApis=new LinkedHashMap<String,RestDocumentation.RestApi>();
  for (  RestDocumentation doc : docs) {
    for (    RestDocumentation.RestApi api : doc.getApis()) {
      if (!aggregatedApis.containsKey(api.getApiBaseUrl())) {
        aggregatedApis.put(api.getApiBaseUrl(),api);
      }
 else {
        aggregatedApis.get(api.getApiBaseUrl()).merge(api);
      }
    }
  }
  Collection<RestDocumentation.RestApi> filteredApis=null;
  if (excludePatterns != null) {
    filteredApis=new LinkedList<RestDocumentation.RestApi>();
    for (    RestDocumentation.RestApi api : aggregatedApis.values())     filteredApis.add(api.filter(excludePatterns));
  }
 else {
    filteredApis=aggregatedApis.values();
  }
  if (!scope.equals("String_Node_Str")) {
    HashSet<String> requestedScopes=new HashSet<String>(Arrays.asList(new String[]{scope}));
    Iterator<RestDocumentation.RestApi> apiIter=filteredApis.iterator();
    while (apiIter.hasNext()) {
      RestDocumentation.RestApi api=apiIter.next();
      Iterator<RestDocumentation.RestApi.Resource> resIter=api.getResources().iterator();
      while (resIter.hasNext()) {
        RestDocumentation.RestApi.Resource resource=resIter.next();
        Iterator<RestDocumentation.RestApi.Resource.Method> methIter=resource.getRequestMethodDocs().iterator();
        while (methIter.hasNext()) {
          HashSet<String> scopes=methIter.next().getScopes();
          scopes.retainAll(requestedScopes);
          if (scopes.isEmpty()) {
            methIter.remove();
          }
        }
        if (resource.getRequestMethodDocs().isEmpty()) {
          resIter.remove();
        }
      }
      if (api.getResources().isEmpty()) {
        apiIter.remove();
      }
    }
  }
  Configuration conf=new Configuration();
  conf.setClassForTemplateLoading(RestDocAssembler.class,"String_Node_Str");
  conf.setObjectWrapper(new DefaultObjectWrapper());
  Writer out=null;
  try {
    for (    RestDocumentation.RestApi api : filteredApis) {
      Template template=conf.getTemplate(_outputTemplate);
      Map<String,RestDocumentation.RestApi> root=new HashMap<String,RestDocumentation.RestApi>();
      root.put("String_Node_Str",api);
      String fileName=getOutputFileName(api);
      filesWritten.add(fileName);
      File file=new File(fileName);
      out=new FileWriter(file);
      template.process(root,out);
      out.flush();
      System.err.printf("String_Node_Str",file.getAbsolutePath());
    }
  }
  finally {
    if (out != null) {
      try {
        out.close();
      }
 catch (      IOException ignored) {
      }
    }
  }
  return filesWritten;
}

Fixed version (ground truth):
List<String> writeDocumentation(List<RestDocumentation> docs,Iterable<Pattern> excludePatterns,String scope) throws IOException, ClassNotFoundException, TemplateException {
  List<String> filesWritten=new ArrayList<String>();
  Map<String,RestDocumentation.RestApi> aggregatedApis=new LinkedHashMap<String,RestDocumentation.RestApi>();
  for (  RestDocumentation doc : docs) {
    for (    RestDocumentation.RestApi api : doc.getApis()) {
      if (!aggregatedApis.containsKey(api.getIdentifier())) {
        aggregatedApis.put(api.getIdentifier(),api);
      }
 else {
        aggregatedApis.get(api.getIdentifier()).merge(api);
      }
    }
  }
  Collection<RestDocumentation.RestApi> filteredApis=null;
  if (excludePatterns != null) {
    filteredApis=new LinkedList<RestDocumentation.RestApi>();
    for (    RestDocumentation.RestApi api : aggregatedApis.values())     filteredApis.add(api.filter(excludePatterns));
  }
 else {
    filteredApis=aggregatedApis.values();
  }
  if (!scope.equals("String_Node_Str")) {
    HashSet<String> requestedScopes=new HashSet<String>(Arrays.asList(new String[]{scope}));
    Iterator<RestDocumentation.RestApi> apiIter=filteredApis.iterator();
    while (apiIter.hasNext()) {
      RestDocumentation.RestApi api=apiIter.next();
      Iterator<RestDocumentation.RestApi.Resource> resIter=api.getResources().iterator();
      while (resIter.hasNext()) {
        RestDocumentation.RestApi.Resource resource=resIter.next();
        Iterator<RestDocumentation.RestApi.Resource.Method> methIter=resource.getRequestMethodDocs().iterator();
        while (methIter.hasNext()) {
          HashSet<String> scopes=methIter.next().getScopes();
          scopes.retainAll(requestedScopes);
          if (scopes.isEmpty()) {
            methIter.remove();
          }
        }
        if (resource.getRequestMethodDocs().isEmpty()) {
          resIter.remove();
        }
      }
      if (api.getResources().isEmpty()) {
        apiIter.remove();
      }
    }
  }
  Configuration conf=new Configuration();
  conf.setClassForTemplateLoading(RestDocAssembler.class,"String_Node_Str");
  conf.setObjectWrapper(new DefaultObjectWrapper());
  Writer out=null;
  try {
    for (    RestDocumentation.RestApi api : filteredApis) {
      Template template=conf.getTemplate(_outputTemplate);
      Map<String,RestDocumentation.RestApi> root=new HashMap<String,RestDocumentation.RestApi>();
      root.put("String_Node_Str",api);
      String fileName=getOutputFileName(api);
      filesWritten.add(fileName);
      File file=new File(fileName);
      out=new FileWriter(file);
      template.process(root,out);
      out.flush();
      System.err.printf("String_Node_Str",file.getAbsolutePath());
    }
  }
  finally {
    if (out != null) {
      try {
        out.close();
      }
 catch (      IOException ignored) {
      }
    }
  }
  return filesWritten;
}