Skip to content

Commit

Permalink
SUREFIRE-2212: parse element content only if needed to prevent OOME
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramon Bisswanger committed Nov 17, 2023
1 parent 47c5816 commit f04a308
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public final class TestSuiteXmlParser extends DefaultHandler {

private boolean valid;

private boolean parseContent;

public TestSuiteXmlParser(ConsoleLogger consoleLogger) {
this.consoleLogger = consoleLogger;
}
Expand Down Expand Up @@ -157,12 +159,14 @@ public void startElement(String uri, String localName, String qName, Attributes
break;
case "failure":
currentElement = new StringBuilder();
parseContent = true;

testCase.setFailure(attributes.getValue("message"), attributes.getValue("type"));
currentSuite.incrementNumberOfFailures();
break;
case "error":
currentElement = new StringBuilder();
parseContent = true;

testCase.setError(attributes.getValue("message"), attributes.getValue("type"));
currentSuite.incrementNumberOfErrors();
Expand All @@ -181,6 +185,7 @@ public void startElement(String uri, String localName, String qName, Attributes
break;
case "time":
currentElement = new StringBuilder();
parseContent = true;
break;
default:
break;
Expand Down Expand Up @@ -215,6 +220,7 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
default:
break;
}
parseContent = false;
// TODO extract real skipped reasons
}

Expand All @@ -225,7 +231,7 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
public void characters(char[] ch, int start, int length) {
assert start >= 0;
assert length >= 0;
if (valid && isNotBlank(start, length, ch)) {
if (valid && parseContent && isNotBlank(start, length, ch)) {
currentElement.append(ch, start, length);
}
}
Expand Down

0 comments on commit f04a308

Please sign in to comment.