Bug 54147

Summary: Creation of the test report (xml, plain) ends with a java.lang.OutOfMemoryError exception
Product: Ant Reporter: Branislav Hanáček <branislav.hanacek>
Component: CoreAssignee: Ant Notifications List <notifications>
Status: RESOLVED FIXED    
Severity: major CC: dtrebbien, jglick
Priority: P2 Keywords: PatchAvailable
Version: 1.9.1   
Target Milestone: 1.9.4   
Hardware: PC   
OS: All   
Attachments: Patch for the DOMElementWriter class
Alternative patch
Test program

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