[英]How to fix : java.lang.OutOfMemoryError: Requested array size exceeds VM limit, while running Junit for a project
Getting below exception while running Junit , Not sure which part of code leading to this issue: (using ANT - 1.9.4, ANT_OPTS=-Xmx10G) ( )运行 Junit 时出现异常,不确定导致此问题的代码部分:(使用 ANT - 1.9.4,ANT_OPTS=-Xmx10G)()
Tests run: 544, Failures: 1, Errors: 0, Time elapsed: 10,258.816 sec
[junit] Exception in thread "main" java.lang.OutOfMemoryError: Requested array size exceeds VM limit
[junit] at java.lang.StringCoding$StringEncoder.encode(StringCoding.java:300)
[junit] at java.lang.StringCoding.encode(StringCoding.java:344)
[junit] at java.lang.StringCoding.encode(StringCoding.java:387)
[junit] at java.lang.String.getBytes(String.java:958)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter.endTestSuite(PlainJUnitResultFormatter.java:152)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.fireEndTestSuite(JUnitTestRunner.java:619)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:452)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:911)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:768)
The exception is thrown after the tests are run and test report generation starts.运行测试并开始生成测试报告后会引发异常。
This is how junit is configured:这是 junit 的配置方式:
<junit fork="yes" newenvironment="false" haltonfailure="no" failureproperty="junit.failure" printsummary="yes" maxmemory="10096m">
Are you sure you are using ANT 1.9.4?您确定您使用的是 ANT 1.9.4 吗?
Your stacktrace matches the source code of PlainJUnitResultFormatter in ANT version 1.8.4:您的堆栈跟踪与 ANT 版本 1.8.4 中的PlainJUnitResultFormatter的源代码相匹配:
out.write(sb.toString().getBytes());
Whereas in the source code of PlainJUnitResultFormatter in ANT version 1.9.4:而在 ANT 版本 1.9.4 中的PlainJUnitResultFormatter的源代码中:
write(StringUtils.LINE_SEP);
there is no call of String.getBytes()
where the exception occurs.在发生异常的地方没有调用String.getBytes()
。
The reason to ask is this comment from the ANT 1.9.4 release notes :询问的原因是来自ANT 1.9.4 发行说明的评论:
- changes to JUnitTestRunner and PlainJUnitResultFormatter to make OutOfMemoryErrors less likely.更改 JUnitTestRunner 和 PlainJUnitResultFormatter 以降低 OutOfMemoryErrors 的可能性。 Bugzilla Report 45536 Bugzilla 报告 45536
So the solution would be to upgrade to ANT 1.9.4 or later所以解决方案是升级到 ANT 1.9.4 或更高版本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.