[
https://issues.apache.org/jira/browse/SUREFIRE-1909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17366928#comment-17366928
]
Christian Kohlschütter commented on SUREFIRE-1909:
--------------------------------------------------
Hi Tibor, I've attached a project that exposes the bug. Just run with "mvn
test".
As I said above, changing "add-exports" to "add-opens" in that class fixes it.
Here's the relevant output from "mvn -X test"
{code:java}
[DEBUG] Determined Maven Process ID 15092
[DEBUG] Fork Channel [1] connection string 'pipe://1' for the implementation
class org.apache.maven.plugin.surefire.extensions.LegacyForkChannel
[DEBUG] boot classpath:
.m2/repository/org/apache/maven/surefire/surefire-booter/3.0.0-M5/surefire-booter-3.0.0-M5.jar
.m2/repository/org/apache/maven/surefire/surefire-api/3.0.0-M5/surefire-api-3.0.0-M5.jar
.m2/repository/org/apache/maven/surefire/surefire-logger-api/3.0.0-M5/surefire-logger-api-3.0.0-M5.jar
.m2/repository/org/apache/maven/surefire/surefire-shared-utils/3.0.0-M4/surefire-shared-utils-3.0.0-M4.jar
.m2/repository/org/apache/maven/surefire/surefire-extensions-spi/3.0.0-M5/surefire-extensions-spi-3.0.0-M5.jar
workspace/surefire-jpms-bug/target/test-classes
.m2/repository/org/junit/jupiter/junit-jupiter/5.7.1/junit-jupiter-5.7.1.jar
.m2/repository/org/junit/jupiter/junit-jupiter-api/5.7.1/junit-jupiter-api-5.7.1.jar
.m2/repository/org/apiguardian/apiguardian-api/1.1.0/apiguardian-api-1.1.0.jar
.m2/repository/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar
.m2/repository/org/junit/platform/junit-platform-commons/1.7.1/junit-platform-commons-1.7.1.jar
.m2/repository/org/junit/jupiter/junit-jupiter-params/5.7.1/junit-jupiter-params-5.7.1.jar
.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.7.1/junit-jupiter-engine-5.7.1.jar
.m2/repository/org/junit/platform/junit-platform-engine/1.7.1/junit-platform-engine-1.7.1.jar
.m2/repository/org/apache/maven/surefire/surefire-junit-platform/3.0.0-M5/surefire-junit-platform-3.0.0-M5.jar
.m2/repository/org/apache/maven/surefire/common-java5/3.0.0-M5/common-java5-3.0.0-M5.jar
.m2/repository/org/junit/platform/junit-platform-launcher/1.7.1/junit-platform-launcher-1.7.1.jar
[DEBUG] boot(compact) classpath: surefire-booter-3.0.0-M5.jar
surefire-api-3.0.0-M5.jar surefire-logger-api-3.0.0-M5.jar
surefire-shared-utils-3.0.0-M4.jar surefire-extensions-spi-3.0.0-M5.jar
test-classes junit-jupiter-5.7.1.jar junit-jupiter-api-5.7.1.jar
apiguardian-api-1.1.0.jar opentest4j-1.2.0.jar junit-platform-commons-1.7.1.jar
junit-jupiter-params-5.7.1.jar junit-jupiter-engine-5.7.1.jar
junit-platform-engine-1.7.1.jar surefire-junit-platform-3.0.0-M5.jar
common-java5-3.0.0-M5.jar junit-platform-launcher-1.7.1.jar
[DEBUG] Path to args file:
workspace/surefire-jpms-bug/target/surefire/surefireargs12553641456609995297
[DEBUG] args file content:
--module-path
"workspace/surefire-jpms-bug/target/classes"
--class-path
".m2/repository/org/apache/maven/surefire/surefire-booter/3.0.0-M5/surefire-booter-3.0.0-M5.jar:.m2/repository/org/apache/maven/surefire/surefire-api/3.0.0-M5/surefire-api-3.0.0-M5.jar:.m2/repository/org/apache/maven/surefire/surefire-logger-api/3.0.0-M5/surefire-logger-api-3.0.0-M5.jar:.m2/repository/org/apache/maven/surefire/surefire-shared-utils/3.0.0-M4/surefire-shared-utils-3.0.0-M4.jar:.m2/repository/org/apache/maven/surefire/surefire-extensions-spi/3.0.0-M5/surefire-extensions-spi-3.0.0-M5.jar:workspace/surefire-jpms-bug/target/test-classes:.m2/repository/org/junit/jupiter/junit-jupiter/5.7.1/junit-jupiter-5.7.1.jar:.m2/repository/org/junit/jupiter/junit-jupiter-api/5.7.1/junit-jupiter-api-5.7.1.jar:.m2/repository/org/apiguardian/apiguardian-api/1.1.0/apiguardian-api-1.1.0.jar:.m2/repository/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar:.m2/repository/org/junit/platform/junit-platform-commons/1.7.1/junit-platform-commons-1.7.1.jar:.m2/repository/org/junit/jupiter/junit-jupiter-params/5.7.1/junit-jupiter-params-5.7.1.jar:.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.7.1/junit-jupiter-engine-5.7.1.jar:.m2/repository/org/junit/platform/junit-platform-engine/1.7.1/junit-platform-engine-1.7.1.jar:.m2/repository/org/apache/maven/surefire/surefire-junit-platform/3.0.0-M5/surefire-junit-platform-3.0.0-M5.jar:.m2/repository/org/apache/maven/surefire/common-java5/3.0.0-M5/common-java5-3.0.0-M5.jar:.m2/repository/org/junit/platform/junit-platform-launcher/1.7.1/junit-platform-launcher-1.7.1.jar"
--patch-module
surefire.jpms.bug="workspace/surefire-jpms-bug/target/test-classes"
--add-exports
surefire.jpms.bug/surefire.test=ALL-UNNAMED
--add-modules
surefire.jpms.bug
--add-reads
surefire.jpms.bug=ALL-UNNAMED
org.apache.maven.surefire.booter.ForkedBooter
[DEBUG] Forking command line: /bin/sh -c cd workspace/surefire-jpms-bug &&
/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin/java
@workspace/surefire-jpms-bug/target/surefire/surefireargs12553641456609995297
workspace/surefire-jpms-bug/target/surefire 2021-06-21T18-41-15_153-jvmRun1
surefire8660924379138157795tmp surefire_015925150141917337177tmp
[DEBUG] Fork Channel [1] connected to the client.
[INFO] Running surefire.test.JupiterTest
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.058 s
<<< FAILURE! - in surefire.test.JupiterTest
[ERROR] surefire.test.JupiterTest.test Time elapsed: 0.013 s <<< ERROR!
java.lang.reflect.InaccessibleObjectException: Unable to make
surefire.test.JupiterTest() accessible: module surefire.jpms.bug does not
"opens surefire.test" to unnamed module @17a7f733
[DEBUG] Closing the fork 1 after saying GoodBye.
[INFO]
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR] JupiterTest.test » InaccessibleObject Unable to make
surefire.test.JupiterTest...
[INFO]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.070 s
[INFO] Finished at: 2021-06-21T18:41:17-07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test (default-test) on
project surefire-jpms-bug: There are test failures.
[ERROR]
[ERROR] Please refer to workspace/surefire-jpms-bug/target/surefire-reports for
the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump,
[date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal
org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test (default-test) on
project surefire-jpms-bug: There are test failures.
Please refer to workspace/surefire-jpms-bug/target/surefire-reports for the
individual test results.
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump
and [date].dumpstream.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute
(MojoExecutor.java:215)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute
(MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute
(MojoExecutor.java:148)
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:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced
(Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode
(Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoFailureException: There are test
failures.
Please refer to workspace/surefire-jpms-bug/target/surefire-reports for the
individual test results.
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump
and [date].dumpstream.
at org.apache.maven.plugin.surefire.SurefireHelper.throwException
(SurefireHelper.java:271)
at org.apache.maven.plugin.surefire.SurefireHelper.reportExecution
(SurefireHelper.java:159)
at org.apache.maven.plugin.surefire.SurefirePlugin.handleSummary
(SurefirePlugin.java:453)
at
org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked
(AbstractSurefireMojo.java:1175)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute
(AbstractSurefireMojo.java:932)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo
(DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute
(MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute
(MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute
(MojoExecutor.java:148)
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:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced
(Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode
(Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please
read the following articles:
[ERROR] [Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
{code}
> Support JUnit 5 reflection access by changing add-exports to add-opens
> ----------------------------------------------------------------------
>
> Key: SUREFIRE-1909
> URL: https://issues.apache.org/jira/browse/SUREFIRE-1909
> Project: Maven Surefire
> Issue Type: Bug
> Components: JUnit 5.x support
> Affects Versions: 3.0.0-M5
> Reporter: Christian Kohlschütter
> Priority: Major
> Attachments: surefire-jpms-bug.tar.gz
>
>
> Testing JUnit 5 classes of a JPMS-enabled project with Surefire may fail if a
> test class (or, for example, an abstract test base class) is not declared
> "public". I'm seeing the following error:
>
> {code:java}
> java.lang.reflect.InaccessibleObjectException: Unable to make public static
> void some.package.SomeClass.setupClass() throws java.io.IOException
> accessible: module some.module does not "opens some.package" to unnamed
> module @754ba872{code}
> This could be fixed by adding the recommended "{{opens some.package}}" to the
> project's module-info.java, however that is undesirable since it changes the
> project's behavior beyond just unit testing. Adding a secondary "test-only"
> module-info.java is also counterproductive since not all IDEs support this,
> and these two files would have to be kept in sync, which is non-trivial.
> An easy fix would be to change the "{{--add-exports}}" VM parameter that
> surefire adds automatically to "{{--}}{{add-opens}}" in
> {{maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfiguration.java}}
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)