Not a bug, but might help

56 views
Skip to first unread message

ghegstrom

unread,
Aug 30, 2011, 11:04:42 AM8/30/11
to testng-dev
I am seeing out of memory issues with a particularly large XML report.

[testng] Exception in thread "main" java.lang.OutOfMemoryError:
Java heap space
[testng] at java.util.Arrays.copyOf(Arrays.java:2882)
[testng] at
java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:
100)
[testng] at
java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:572)
[testng] at java.lang.StringBuilder.append(StringBuilder.java:
203)
[testng] at
org.testng.internal.Utils.escapeUnicode(Utils.java:548)
[testng] at
org.testng.internal.Utils.writeUtf8File(Utils.java:113)
[testng] at
org.testng.reporters.XMLReporter.generateReport(XMLReporter.java:65)
[testng] at org.testng.TestNG.generateReports(TestNG.java:
1053)
[testng] at org.testng.TestNG.run(TestNG.java:1016)
[testng] at org.testng.TestNG.privateMain(TestNG.java:1301)
[testng] at org.testng.TestNG.main(TestNG.java:1265)
[testng] The tests failed.

Looking at Utils.java, I noticed that escapeUnicode() has the
following line (543):
StringBuilder result = new StringBuilder();

I think the resulting string will always be at least as long as the
input string, so it seems like that line should be changed to:
StringBuilder result = new StringBuilder(s.Length());

That should prevent 17 or so reallocations and mem_copies when the
string is around 1 MB in size.

Of course, whether we should have a file that big is a different
question, and obviously I can increase the available memory, but
initializing the StringBuilder to a known size seems more efficient
regardless.

Thanks,
-Greg

Cédric Beust ♔

unread,
Aug 30, 2011, 12:40:35 PM8/30/11
to testn...@googlegroups.com
Hi Greg,

Thanks for the report. Did you actually verify that your suggestion fixes the problem? If yes, I'll apply it (or feel free to send me a pull request).

-- 
Cédric





--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To post to this group, send email to testn...@googlegroups.com.
To unsubscribe from this group, send email to testng-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-dev?hl=en.


Michael Ondrejko

unread,
Oct 3, 2012, 10:47:59 PM10/3/12
to testn...@googlegroups.com
Have you tried out your suggestion and did it fix the issue? If so, in what version is the fix available?
Reply all
Reply to author
Forward
0 new messages