Java Surefire Maven 插件:“通过直接写入分叉 JVM 中的本机流来破坏 STDOUT”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/55272870/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Surefire Maven plugin: "Corrupted STDOUT by directly writing to native stream in forked JVM"
提问by user118967
My JUnit tests are failing when running them through Maven and the Surefire plugin (version information below). I see the error message:
我的 JUnit 测试在通过 Maven 和 Surefire 插件(版本信息如下)运行时失败。我看到错误消息:
Corrupted STDOUT by directly writing to native stream in forked JVM 4. See FAQ web page and the dump file C:\(...)\target\surefire-reports19-03-20T18-57-17_082-jvmRun4.dumpstream
The FAQ page points out some possible reasons but I don't see how I can use this information to start solving this problem:
FAQ 页面指出了一些可能的原因,但我不知道如何使用这些信息来解决这个问题:
Corrupted STDOUT by directly writing to native stream in forked JVM
If your tests use native library which prints to STDOUT this warning message appears because the library corrupted the channel used by the plugin in order to transmit events with test status back to Maven process. It would be even worse if you override the Java stream by System.setOut because the stream is also supposed to be corrupted but the Maven will never see the tests finished and build may hang.
This warning message appears if you use FileDescriptor.out or JVM prints GC summary.
In that case the warning is printed "Corrupted STDOUT by directly writing to native stream in forked JVM", and a dump file can be found in Reports directory.
If debug level is enabled then messages of corrupted stream appear in the console.
通过直接写入分叉 JVM 中的本机流来损坏 STDOUT
如果您的测试使用打印到 STDOUT 的本机库,则会出现此警告消息,因为该库损坏了插件使用的通道,以便将具有测试状态的事件传输回 Maven 进程。如果您通过 System.setOut 覆盖 Java 流会更糟,因为该流也应该已损坏,但 Maven 永远不会看到测试完成并且构建可能会挂起。
如果您使用 FileDescriptor.out 或 JVM 打印 GC 摘要,则会出现此警告消息。
在这种情况下,会打印警告“Corrupted STDOUT by direct write to native stream in forked JVM”,并且可以在 Reports 目录中找到转储文件。
如果启用了调试级别,则控制台中会出现损坏流的消息。
It refers to some native library printing out to STDOUT directly but how can I figure out which one, and even if I do, how do I deal with this issue if I need the library for my project?
它指的是一些直接打印到 STDOUT 的本机库,但我如何确定是哪一个,即使我知道,如果我的项目需要该库,我该如何处理这个问题?
It mentions "debug level" but it is unclear if this means Maven's debug level or Surefire plugin's debug level. I enabled Maven's debug but I don't see the console outputs as mentioned by the FAQ. And Surefire's debug option seems to be about pausing tests and waiting for a debugger to be connected to the process, not simply showing more information on the console.
它提到了“调试级别”,但不清楚这是否意味着 Maven 的调试级别或 Surefire 插件的调试级别。我启用了 Maven 的调试,但我没有看到常见问题解答中提到的控制台输出。而 Surefire 的调试选项似乎是关于暂停测试并等待调试器连接到进程,而不是简单地在控制台上显示更多信息。
The dump files also don't seem very helpful:
转储文件似乎也不是很有帮助:
# Created on 2019-03-20T18:42:58.323
Corrupted STDOUT by directly writing to native stream in forked JVM 2. Stream 'FATAL ERROR in native method: processing of -javaagent failed'.
java.lang.IllegalArgumentException: Stream stdin corrupted. Expected comma after third character in command 'FATAL ERROR in native method: processing of -javaagent failed'.
at org.apache.maven.plugin.surefire.booterclient.output.ForkClient$OperationalData.<init>(ForkClient.java:511)
at org.apache.maven.plugin.surefire.booterclient.output.ForkClient.processLine(ForkClient.java:209)
at org.apache.maven.plugin.surefire.booterclient.output.ForkClient.consumeLine(ForkClient.java:176)
at org.apache.maven.plugin.surefire.booterclient.output.ThreadedStreamConsumer$Pumper.run(ThreadedStreamConsumer.java:88)
at java.base/java.lang.Thread.run(Thread.java:834)
So, how can I solve this problem?
那么,我该如何解决这个问题呢?
Update: requested configuration information below.
更新:请求下面的配置信息。
I'm using OpenJDK 11 (Zulu distribution) on Windows 10, Maven 3.5.3, and Surefire 2.21.0 (full configuration below).
我在 Windows 10、Maven 3.5.3 和 Surefire 2.21.0(完整配置如下)上使用 OpenJDK 11(Zulu 发行版)。
I'm running Maven from Eclipse using the "Run As..." context menu option on the pom.xml
file, but obtain the same results when running it on the console.
我正在使用文件上的“运行方式...”上下文菜单选项从 Eclipse 运行 Maven pom.xml
,但在控制台上运行它时获得相同的结果。
I had never heard of JaCoco before the first comment to this question, but I see several error messages mentioning it:
在对这个问题发表第一条评论之前,我从未听说过 JaCoco,但我看到几条错误消息提到了它:
[ERROR] ExecutionException The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was cmd.exe /X /C ""C:\Program Files\Zulu\zulu-11\bin\java" -javaagent:C:\Users\E26638\.m2\repository\org\jacoco\org.jacoco.agent\0.8.0\org.jacoco.agent-0.8.0-runtime.jar=destfile=C:\Users\E26638\git\aic-expresso\target\jacoco.exec -Xms256m -Xmx1028m -jar C:\Users\E26638\AppData\Local\Temp\surefire10089630030045878403\surefirebooter8801585361488929382.jar C:\Users\E26638\AppData\Local\Temp\surefire10089630030045878403 2019-03-21T21-26-04_829-jvmRun12 surefire10858509118810158083tmp surefire_115439010304069944813tmp"
[ERROR] Error occurred in starting fork, check output in log
[ERROR] Process Exit Code: 1
This is the Surefire Maven plugin configuration:
这是 Surefire Maven 插件配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<skipTests>${skipUnitTests}</skipTests>
<testFailureIgnore>false</testFailureIgnore>
<forkCount>1.5C</forkCount>
<reuseForks>true</reuseForks>
<parallel>methods</parallel>
<threadCount>4</threadCount>
<perCoreThreadCount>true</perCoreThreadCount>
<reportFormat>plain</reportFormat>
<trimStackTrace>false</trimStackTrace>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
</configuration>
</plugin>
采纳答案by Nemesis
Run in the same problem while migrating project from JAVA 8 to JAVA 11, upgrading jacoco-plugin from 0.8.1 to 0.8.4 did the job.
将项目从 JAVA 8 迁移到 JAVA 11 时遇到同样的问题,将 jacoco-plugin 从 0.8.1 升级到 0.8.4 完成了这项工作。
Analysing maven dependencies, seeing from where jacoco is pulled and then fixing the version should solve the issue.
分析 maven 依赖项,查看 jacoco 的拉取位置,然后修复版本应该可以解决问题。
回答by Prabhu P
The error is due to JRE incompatibility. Lower the version of JRE to 7 or 8.
该错误是由于 JRE 不兼容造成的。将 JRE 的版本降低到 7 或 8。
回答by Petar Tahchiev
For me it was updating the failsafe plugin from 2.22.0 to 2.22.2
对我来说,它是将故障安全插件从 2.22.0 更新到 2.22.2
回答by jhas
What solved it for me is upgrading maven surefire plugin to 2.22.2
为我解决的是将 maven surefire 插件升级到 2.22.2
回答by Werner Keil
The newer Surefire plugin versions are completely buggy and broken. for me (tested all the way up to Java 12) the only solution was to stick with 2.20.
较新的 Surefire 插件版本完全有问题且已损坏。对我来说(一直测试到 Java 12)唯一的解决方案是坚持使用2.20。
Don't use 2.20.1 either, that failed with a NPE, although maybe it is specific to particular tests, but I don't have time to investigate that.
也不要使用 2.20.1,它因 NPE 而失败,尽管它可能特定于特定测试,但我没有时间对此进行调查。
回答by Patrick
I was running into this issue when running my Junit tests using a custom Runner. If I made any output to System.out
or System.err
in my custom runner or in my test class, this exact warning would show up. In my case the problem was not caused by some older Jacoco version. Updating the surefire plugin to version 2.22.2 or the more recent 3.0.0-M4 did not solve the issue.
我在使用自定义 Runner 运行 Junit 测试时遇到了这个问题。如果我做的任何输出System.out
或者System.err
在我定制的运行或在我的测试类,这个确切的警告会出现。在我的情况下,问题不是由某些较旧的 Jacoco 版本引起的。将 surefire 插件更新到版本 2.22.2 或更新的 3.0.0-M4 没有解决问题。
According to the Jira issue SUREFIRE-1614, the problem will be fixed in the 3.0.0-M5 release of the maven-surefire-plugin (not released as of May 21st 2020).
根据 Jira 问题 SUREFIRE-1614,该问题将在 maven-surefire-plugin 的 3.0.0-M5 版本中修复(截至 2020 年 5 月 21 日未发布)。
In the meantime, you can use the "SNAPSHOT" version of the plugin. It did fix the issue for me. You have to enable some specific setting in the plugin so that the plugin uses TCP instead of the standard output/error to obtain the events raised in your tests. Configuration changes below:
同时,您可以使用插件的“SNAPSHOT”版本。它确实为我解决了这个问题。您必须在插件中启用某些特定设置,以便插件使用 TCP 而不是标准输出/错误来获取测试中引发的事件。配置更改如下:
In my pom.xml
:
在我的pom.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
...
<!-- Add the repository to download the "SNAPSHOT" of maven-surefire-plugin -->
<pluginRepositories>
<pluginRepository>
<id>apache.snapshots</id>
<url>https://repository.apache.org/snapshots/</url>
</pluginRepository>
</pluginRepositories>
<build>
<pluginManagement>
<plugins>
...
<artifactId>maven-surefire-plugin</artifactId>
<!-- Use the SNAPSHOT version -->
<version>3.0.0-SNAPSHOT</version>
<configuration>
<!-- Activate the use of TCP to transmit events to the plugin -->
<forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory"/>
</configuration>
</plugin>