Details
Description
Example below leads to the infinite loop in LineCountParser
<p></p><pre>i < 3</pre>
which continuously receives SAXParseException :
org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 16; The markup in the document following the root element must be well-formed. at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source) at org.apache.xerces.impl.XMLDocumentScannerImpl$TrailingMiscDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source) at javax.xml.parsers.SAXParser.parse(SAXParser.java:195) at org.sonar.plugins.xml.parsers.LineCountParser.countLinesOfComment(LineCountParser.java:122)
The infinite loop was caused by the "continue-after-fatal-error" feature of Xerces. I think this feature was enabled in the hope of managing to count comment lines even on malformed XML files. But according to [1] this feature is not safe and can lead to infinite loop, OOM, NPE, ...
As a result I have disabled it.
As a result there is no more line count on malformed inputs.
[1] http://permalink.gmane.org/gmane.text.xml.xerces-j.user/4928