Skip to content

Fix IllegalAccessError when the main module requires JUnit (#3532) - #3538

Merged
olamy merged 2 commits into
apache:masterfrom
olamy:issue-3532-main-module-requires-junit
Oct 18, 2026
Merged

olamy merged 2 commits into
apache:masterfrom
olamy:issue-3532-main-module-requires-junit

Conversation

@olamy

@olamy olamy commented Oct 18, 2026

Copy link
Copy Markdown
Member

When the main module-info requires JUnit, JUnit goes on the module path
while the launcher, the engines and the provider stay on the class path,
so the fork failed before running any test.

Signed-off-by: Olivier Lamy olamy@apache.org


To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
check one of the following:

When the main module-info requires JUnit, JUnit goes on the module path
while the launcher, the engines and the provider stay on the class path,
so the fork failed before running any test.

Signed-off-by: Olivier Lamy <olamy@apache.org>
Signed-off-by: Olivier Lamy <olamy@apache.org>
@olamy
olamy merged commit a343e4d into apache:master Oct 18, 2026
16 checks passed
@olamy
olamy requested a balanced review from Copilot October 18, 2026 11:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟒 Approval recommended

Static review found no blocking issues, with focused unit and integration coverage present; tests were not executed.

No open issues πŸŽ‰

What changed in this PR

Fixes fork startup when the main module requires JUnit, allowing module-path JUnit libraries to work with classpath engines and providers.

Changes:

  • Generates module exports and test-package opens from resolved module descriptors.
  • Combines these arguments with provider arguments without modifying provider-owned lists.
  • Adds unit coverage and JUnit 5/6 integration fixtures.
File Description
surefire-its/​src/​test/​resources/​surefire-3532-main-module-requires-junit/​src/​test/​java/​issue3532/​TimeoutTest.java Covers separate-thread timeout execution.
surefire-its/​src/​test/​resources/​surefire-3532-main-module-requires-junit/​src/​test/​java/​issue3532/​internal/​InternalTest.java Covers tests in an internal package.
surefire-its/​src/​test/​resources/​surefire-3532-main-module-requires-junit/​src/​test/​java/​issue3532/​ChecksTest.java Covers package-private test access.
surefire-its/​src/​test/​resources/​surefire-3532-main-module-requires-junit/​src/​main/​java/​module-info.java Declares the main module’s JUnit requirement.
surefire-its/​src/​test/​resources/​surefire-3532-main-module-requires-junit/​src/​main/​java/​issue3532/​Checks.java Provides a JUnit-dependent main-code helper.
surefire-its/​src/​test/​resources/​surefire-3532-main-module-requires-junit/​pom.xml Configures the modular regression fixture.
surefire-its/​src/​test/​java/​org/​apache/​maven/​surefire/​its/​jiras/​Surefire3532MainModuleRequiresJUnitIT.java Checks JUnit 5/6 execution and warning-free arguments.
maven-surefire-common/​src/​test/​java/​org/​apache/​maven/​plugin/​surefire/​ModulePathJpmsArgumentsTest.java Tests argument generation and edge cases.
maven-surefire-common/​src/​test/​java/​org/​apache/​maven/​plugin/​surefire/​AbstractSurefireMojoJava7PlusTest.java Checks startup integration and immutable provider lists.
maven-surefire-common/​src/​main/​java/​org/​apache/​maven/​plugin/​surefire/​ModulePathJpmsArguments.java Generates module access arguments.
maven-surefire-common/​src/​main/​java/​org/​apache/​maven/​plugin/​surefire/​AbstractSurefireMojo.java Adds generated arguments to modular fork configuration.

Review effort: Balanced

@desruisseaux

Copy link
Copy Markdown

For information, this pull request and #3523 seems to add heuristic rules. When we will start the work for adding Java module support in the Maven 4 way, we may need to disable all those heuristic rules (they will be used only for compatibility with Maven 3 way). Therefore, if there is some way to group heuristic rules in a place that we can easily identity and enable/disable when needed, that may be helpful.

For example, in the Maven 4 way, whether to put a dependency on the class-path or module-path should not be decided by the plugin anymore. It should be decided by Maven core and depends, among other, of the dependency type (e.g. jar, classpath-jar or modular-jar)

@olamy

olamy commented Oct 19, 2026

Copy link
Copy Markdown
Member Author

For information, this pull request and #3523 seems to add heuristic rules. When we will start the work for adding Java module support in the Maven 4 way, we may need to disable all those heuristic rules (they will be used only for compatibility with Maven 3 way). Therefore, if there is some way to group heuristic rules in a place that we can easily identity and enable/disable when needed, that may be helpful.

For example, in the Maven 4 way, whether to put a dependency on the class-path or module-path should not be decided by the plugin anymore. It should be decided by Maven core and depends, among other, of the dependency type (e.g. jar, classpath-jar or modular-jar)

Looks like a very good idea. Thanks
Done here #3541

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Modular project that requires transitive org.junit.jupiter.api fails with IllegalAccessError

3 participants