Description: | In line 177 of JUnitXMLReporter, synchronized collection m_configIssues is iterated
in an unsynchronized manner, but according to Oracle Java 7 API specification,
although a synchronizedList is thread-safe for list manipulations like insertion and
deletion, manual synchronization is required when the collection is iterated.
Failure to do so might result in non-deterministic behavior.
The fix synchronizes m_configIssues when iterating. |
Code with Misuse: |
class JUnitXMLReporter { /** * generate the XML report given what we know from all the test results */ protected void generateReport(ITestContext context) {
XMLStringBuffer document= new XMLStringBuffer(); document.addComment("Generated by " + getClass().getName());
Properties attrs= new Properties(); attrs.setProperty(XMLConstants.ATTR_ERRORS, "0"); attrs.setProperty(XMLConstants.ATTR_FAILURES, "" + m_numFailed); try { attrs.setProperty(XMLConstants.ATTR_HOSTNAME, InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException e) { // ignore } Set<String> packages = getPackages(context); if (packages.size() > 0) { attrs.setProperty(XMLConstants.ATTR_NAME, context.getCurrentXmlTest().getName()); // attrs.setProperty(XMLConstants.ATTR_PACKAGE, packages.iterator().next()); }
attrs.setProperty(XMLConstants.ATTR_TESTS, "" + m_allTests.size()); attrs.setProperty(XMLConstants.ATTR_TIME, "" + ((context.getEndDate().getTime() - context.getStartDate().getTime()) / 1000.0));
Date timeStamp = Calendar.getInstance().getTime(); attrs.setProperty(XMLConstants.ATTR_TIMESTAMP, timeStamp.toGMTString());
document.push(XMLConstants.TESTSUITE, attrs); // document.addEmptyElement(XMLConstants.PROPERTIES);
for(ITestResult tr : m_configIssues) { createElement(document, tr); } for(ITestResult tr : m_allTests) { createElement(document, tr); }
document.pop(); Utils.writeUtf8File(context.getOutputDirectory(),generateFileName(context) + ".xml", document.toXML()); }
}
|