Skip to content

Commit f04a308

Browse files
author
Ramon Bisswanger
committed
SUREFIRE-2212: parse element content only if needed to prevent OOME
1 parent 47c5816 commit f04a308

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public final class TestSuiteXmlParser extends DefaultHandler {
6060

6161
private boolean valid;
6262

63+
private boolean parseContent;
64+
6365
public TestSuiteXmlParser(ConsoleLogger consoleLogger) {
6466
this.consoleLogger = consoleLogger;
6567
}
@@ -157,12 +159,14 @@ public void startElement(String uri, String localName, String qName, Attributes
157159
break;
158160
case "failure":
159161
currentElement = new StringBuilder();
162+
parseContent = true;
160163

161164
testCase.setFailure(attributes.getValue("message"), attributes.getValue("type"));
162165
currentSuite.incrementNumberOfFailures();
163166
break;
164167
case "error":
165168
currentElement = new StringBuilder();
169+
parseContent = true;
166170

167171
testCase.setError(attributes.getValue("message"), attributes.getValue("type"));
168172
currentSuite.incrementNumberOfErrors();
@@ -181,6 +185,7 @@ public void startElement(String uri, String localName, String qName, Attributes
181185
break;
182186
case "time":
183187
currentElement = new StringBuilder();
188+
parseContent = true;
184189
break;
185190
default:
186191
break;
@@ -215,6 +220,7 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
215220
default:
216221
break;
217222
}
223+
parseContent = false;
218224
// TODO extract real skipped reasons
219225
}
220226

@@ -225,7 +231,7 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
225231
public void characters(char[] ch, int start, int length) {
226232
assert start >= 0;
227233
assert length >= 0;
228-
if (valid && isNotBlank(start, length, ch)) {
234+
if (valid && parseContent && isNotBlank(start, length, ch)) {
229235
currentElement.append(ch, start, length);
230236
}
231237
}

0 commit comments

Comments
 (0)