Bug 54147 - Creation of the test report (xml, plain) ends with a java.lang.OutOfMemoryError exception
Summary: Creation of the test report (xml, plain) ends with a java.lang.OutOfMemoryErr...
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core (show other bugs)
Version: 1.9.1
Hardware: PC All
: P2 major (vote)
Target Milestone: 1.9.4
Assignee: Ant Notifications List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2012-11-15 12:30 UTC by Branislav Hanáček
Modified: 2014-01-06 20:00 UTC (History)
2 users (show)



Attachments
Patch for the DOMElementWriter class (3.60 KB, patch)
2012-11-15 12:30 UTC, Branislav Hanáček
Details | Diff
Alternative patch (3.71 KB, patch)
2012-12-09 15:38 UTC, Daniel Trebbien
Details | Diff
Test program (2.48 KB, text/plain)
2012-12-09 15:45 UTC, Daniel Trebbien
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Branislav Hanáček 2012-11-15 12:30:07 UTC
Created attachment 29601 [details]
Patch for the DOMElementWriter class

Our Unit Test contains keeps failing with java.lang.OutOfMemory exception when the test results are written into the XML/text file.
First problem was solved by applying the patch from patch from the https://issues.apache.org/bugzilla/show_bug.cgi?id=45536.

But it still does not helped, and the exception is still thrown:

[epos junit] Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
[epos junit] 	at java.lang.StringCoding$StringDecoder.decode(StringCoding.java:133)
[epos junit] 	at java.lang.StringCoding.decode(StringCoding.java:173)
[epos junit] 	at java.lang.StringCoding.decode(StringCoding.java:185)
[epos junit] 	at java.lang.String.<init>(String.java:570)
[epos junit] 	at java.lang.String.<init>(String.java:593)
[epos junit] 	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:547)
[epos junit] 	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1052)
[epos junit] 	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:906)

After a short investigation I have found, that the problem lies in the conversion of the DOM representation into the XML/Text file, caused by multiple allocation of the memory for storing of the string data of the CDATA element.

I have skipped the copy of the CDATA into the memory, the data will be written directly into the output stream, instead (see the attached patch).
Comment 1 Daniel Trebbien 2012-12-09 15:35:24 UTC
1.  Rather than moving and renaming the encodedata() method, why not make the necessary changes in place? This way, history is better preserved.

2.  The new implementation is not correct.  It writes out "]]]]><![CDATA[>" as soon as it sees "]]", but this means that "]]>" is replaced with "]]]]><![CDATA[>>".

What you could do is write out "]]]]><![CDATA[" instead.  Though, this slightly changes the behavior (i.e. instead of escaping "]]>", it actually escapes "]]") and the JavaDoc comment would need to be updated.

3.  Because characters are written individually in the new code, there is likely a negative impact on performance.
Comment 3 Daniel Trebbien 2012-12-09 15:45:45 UTC
Created attachment 29735 [details]
Test program

I used this test program to check my suggested implementation of encodedata(Writer, String).
Comment 4 Stefan Bodewig 2014-01-06 20:00:01 UTC
slipped into svn revision 1556001 by accident when it should have been a separate commit.  second part is svn revision 1556004