apache / apache/maven-surefire
[SUREFIRE-1549] Surefire outputs jmockit exception before forking and running JUnit5 / Java 10 tests successfully.
- Dominant language
- Java
- Stars
- 461
- Forks
- 588
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 19
Description
**[Bret Goldsmith](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=bretg)** opened **[SUREFIRE-1549](https://issues.apache.org/jira/browse/SUREFIRE-1549?redirect=false)** and commented
Running this test shows an exception on the build output, but does not affect the actual running of the forked tests.
```
[INFO] --- maven-surefire-plugin:2.22.0:test (default-test) @ sample ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
java.lang.IllegalStateException: Running on JDK 9 requires -javaagent:/jmockit-1.n.jar or -Djdk.attach.allowAttachSelf
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:290)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:194)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[INFO] Running SampleTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.037 s - in SampleTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
```
Test project attached that recreates the issue.
The "-Djdk.attach.allowAttachSelf" config is being passed to the forked runtime and allows the tests to pass, as indicated in the sample project's pom.xml, under the surefire config.
I'm not sure if this is a surefire issue, a junit5 issue, or a jmockit issue, but I think it's a bit of a combination (and consequently have no idea what the right "fix" would target).
After some basic investigation, it looks like Surefire is kicking off the JUnitPlatformProvider, which calls out to LauncherFactory, and all this happens before the fork takes place where the test execution actually runs. At this point, there is some awareness by the code on whether it is running inside a fork or not, and seems to be the part that is trying to look at the various tests in the codebase. At some point, the JMockitTestEngine class gets initialized by the LauncherFactory, and the LauncherFactory is not passing down the context of whether this is running inside a fork or not. JMockit is not aware and tries to attach to the JVM that was invoked by maven. Forking the tests is supposed to avoid that and allow all that config to be passed to the forked JVM, which is working fine. The exception still gets output to the console, and is an annoyance.
---
**Affects:** 2.22.0
**Attachments:**
- [sample.zip](https://issues.apache.org/jira/secure/attachment/12935174/sample.zip) (_1.55 kB_)
Contributor guide
Research direction
Start by unpacking sample.zip and reading the sample project's pom.xml, especially the Surefire configuration and -Djdk.attach.allowAttachSelf setting. Trace the JUnitPlatformProvider, LauncherFactory, and JMockitTestEngine path described in the report; done means the forked JUnit 5 tests still pass without printing the pre-fork JMockit exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100