public final void reportBugsFromXml(@WillClose InputStream in, Project theProject)
     throws IOException, DocumentException {
   SortedBugCollection theCollection = new SortedBugCollection(theProject);
   theCollection.readXML(in);
   for (BugInstance bug : theCollection.getCollection()) {
     doReportBug(bug);
   }
 }
  /**
   * Returns the parsed FindBugs analysis file. This scanner accepts files in the native FindBugs
   * format.
   *
   * @param file the FindBugs analysis file
   * @param sources a collection of folders to scan for source files
   * @param moduleName name of maven module
   * @param hashToMessageMapping mapping of hash codes to messages
   * @param categories mapping from bug types to their categories
   * @return the parsed result (stored in the module instance)
   * @throws IOException if the file could not be parsed
   * @throws DocumentException in case of a parser exception
   */
  private Collection<FileAnnotation> parse(
      final InputStream file,
      final Collection<String> sources,
      final String moduleName,
      final Map<String, String> hashToMessageMapping,
      final Map<String, String> categories)
      throws IOException, DocumentException {
    SortedBugCollection collection = readXml(file);

    Project project = collection.getProject();
    for (String sourceFolder : sources) {
      project.addSourceDir(sourceFolder);
    }

    SourceFinder sourceFinder = new SourceFinder(project);
    String actualName = extractModuleName(moduleName, project);

    TreeStringBuilder stringPool = new TreeStringBuilder();
    List<FileAnnotation> annotations = new ArrayList<FileAnnotation>();
    Collection<BugInstance> bugs = collection.getCollection();

    for (BugInstance warning : bugs) {

      SourceLineAnnotation sourceLine = warning.getPrimarySourceLineAnnotation();

      String message = warning.getMessage();
      String type = warning.getType();
      if (message.contains("TEST: Unknown")) {
        message = FindBugsMessages.getInstance().getShortMessage(type, LocaleProvider.getLocale());
      }
      String category = categories.get(type);
      if (category
          == null) { // alternately, only if warning.getBugPattern().getType().equals("UNKNOWN")
        category = warning.getBugPattern().getCategory();
      }
      Bug bug =
          new Bug(
              getPriority(warning),
              StringUtils.defaultIfEmpty(
                  hashToMessageMapping.get(warning.getInstanceHash()), message),
              category,
              type,
              sourceLine.getStartLine(),
              sourceLine.getEndLine());
      bug.setInstanceHash(warning.getInstanceHash());
      bug.setRank(warning.getBugRank());

      boolean ignore = setCloudInformation(collection, warning, bug);
      if (!ignore) {
        bug.setNotAProblem(false);
        bug.setFileName(findSourceFile(project, sourceFinder, sourceLine));
        bug.setPackageName(warning.getPrimaryClass().getPackageName());
        bug.setModuleName(actualName);
        setAffectedLines(warning, bug);

        annotations.add(bug);
        bug.intern(stringPool);
      }
    }

    return applyFilters(annotations);
  }