private Document endDocument(Project project) { // Save the error information Element errorsElement = root.addElement(ERRORS_ELEMENT_NAME); for (AnalysisError analysisError : bugCollection.getErrors()) { errorsElement.addElement(ANALYSIS_ERROR_ELEMENT_NAME).setText(analysisError.getMessage()); } for (Iterator<String> i = bugCollection.missingClassIterator(); i.hasNext();) { errorsElement.addElement(MISSING_CLASS_ELEMENT_NAME).setText(i.next()); } return document; }
/** * @see <a href="https://github.com/spotbugs/spotbugs/issues/338">GitHub * issue</a> */ @Test public void testIssue338() { BugCollection bugCollection = spotbugs.performAnalysis(Paths.get("../spotbugsTestCases/build/classes/java/main/lambdas/Issue338.class")); assertThat(bugCollection, is(emptyIterable())); assertThat(bugCollection, instanceOf(SortedBugCollection.class)); assertThat(((SortedBugCollection) bugCollection).missingClassIterator().hasNext(), is(false)); } }
@Test public void testLambdas() { performAnalysis("lambdas/Issue547.class"); final BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().build(); SortedBugCollection bugCollection = (SortedBugCollection) getBugCollection(); assertThat(bugCollection, containsExactly(0, bugTypeMatcher)); Iterator<String> missingIter = bugCollection.missingClassIterator(); List<String> strings = new ArrayList<>(); missingIter.forEachRemaining(x -> strings.add(x)); assertEquals(Collections.EMPTY_LIST, strings); }
@Test public void testSimpleLambdas() { performAnalysis("lambdas/Issue527.class"); final BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() .bugType("NP_NULL_ON_SOME_PATH").build(); SortedBugCollection bugCollection = (SortedBugCollection) getBugCollection(); assertThat(bugCollection, containsExactly(2, bugTypeMatcher)); Iterator<String> missingIter = bugCollection.missingClassIterator(); List<String> strings = new ArrayList<>(); missingIter.forEachRemaining(x -> strings.add(x)); assertEquals(Collections.EMPTY_LIST, strings); }
XMLOutputUtil.writeElementList(xmlOutput, MISSING_CLASS_ELEMENT_NAME, missingClassIterator());
private Document endDocument(Project project) { // Save the error information Element errorsElement = root.addElement(ERRORS_ELEMENT_NAME); for (AnalysisError analysisError : bugCollection.getErrors()) { errorsElement.addElement(ANALYSIS_ERROR_ELEMENT_NAME).setText(analysisError.getMessage()); } for (Iterator<String> i = bugCollection.missingClassIterator(); i.hasNext();) { errorsElement.addElement(MISSING_CLASS_ELEMENT_NAME).setText(i.next()); } return document; }
XMLOutputUtil.writeElementList(xmlOutput, MISSING_CLASS_ELEMENT_NAME, missingClassIterator());