Skip to content

Fix: resolve relative classpath elements against the fork's working dir#3333

Merged
olamy merged 6 commits into
apache:masterfrom
cwegener-79:bugfix/relativeAddtionalClasspathElements
Jun 6, 2026
Merged

Fix: resolve relative classpath elements against the fork's working dir#3333
olamy merged 6 commits into
apache:masterfrom
cwegener-79:bugfix/relativeAddtionalClasspathElements

Conversation

@cwegener-79

Copy link
Copy Markdown
Contributor

When Surefire uses a manifest-only JAR to pass the classpath (default on Windows
and for long classpaths), Class-Path entries in the manifest are relative to the
manifest JAR's parent directory - a temp directory, not the fork's working directory.

A relative additionalClasspathElement (e.g. ../resources) was written as-is into
the manifest, where the JVM resolved it against the temp directory instead of the
fork's workingDirectory, silently pointing at the wrong location.

Fix: JarManifestForkConfiguration now resolves relative classpath elements against
the fork's working directory before computing their manifest-relative representation.
All resolveClasspath() implementations receive the resolved working directory as a
new parameter. In direct classpath mode (ClasspathForkConfiguration) no change in
behavior is needed as the JVM already resolves -cp entries against its own CWD.

Adds unit test (ForkConfigurationTest) and integration test
(AdditionalClasspathForkIT / additional-classpath-relative-workdir) to guard
against regression.

Testing

Unit tests pass (mvn clean install).
Integration tests (-PrunIts) could not be executed due to proxy restrictions in my build environment.

Known build issue

mvn clean install fails with the RAT plugin reporting unapproved licenses on generated files inside target/ subdirectories (e.g. checkstyle-cachefile, spotless-index, .plxarc). This appears to be a pre-existing gap in the RAT configuration — target/ is not explicitly excluded. The following addition to the <excludes> block in the root pom.xml would fix it:

<exclude>**/target/**</exclude>

Build can be verified in the meantime with:

mvn clean install -Drat.skip=true


@cwegener-79

Copy link
Copy Markdown
Contributor Author

Hi everyone,

this PR from March 27 is still open — could you please take a moment to review it?
Let me know if anything is missing.

Thanks.

throws SurefireBooterForkException {
cli.addEnvironment("CLASSPATH", join(toCompleteClasspath(config).iterator(), File.pathSeparator));
List<String> classpath = toCompleteClasspath(config);
cli.addEnvironment("CLASSPATH", join(classpath.iterator(), File.pathSeparator));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please limit non needed changes or point via a comment the real fix

@cwegener-79 cwegener-79 force-pushed the bugfix/relativeAddtionalClasspathElements branch from 7f40092 to 03ceb2f Compare June 4, 2026 15:51
…irectory

When Surefire uses a manifest-only JAR to pass the classpath (default on Windows
and for long classpaths), Class-Path entries in the manifest are relative to the
manifest JAR's parent directory - a temp directory, not the fork's working directory.

A relative additionalClasspathElement (e.g. ../resources) was written as-is into
the manifest, where the JVM resolved it against the temp directory instead of the
fork's workingDirectory, silently pointing at the wrong location.

Fix: JarManifestForkConfiguration now resolves relative classpath elements against
the fork's working directory before computing their manifest-relative representation.
All resolveClasspath() implementations receive the resolved working directory as a
new parameter. In direct classpath mode (ClasspathForkConfiguration) no change in
behavior is needed as the JVM already resolves -cp entries against its own CWD.

Adds unit test (ForkConfigurationTest) and integration test
(AdditionalClasspathForkIT / additional-classpath-relative-workdir) to guard
against regression.
@cwegener-79 cwegener-79 force-pushed the bugfix/relativeAddtionalClasspathElements branch from 03ceb2f to c5d24a2 Compare June 4, 2026 15:55
@olamy

olamy commented Jun 4, 2026

Copy link
Copy Markdown
Member

@cwegener-79 thanks for the last changes. just need now a last mvn spotless:apply Thanks

@olamy olamy self-assigned this Jun 6, 2026
@olamy olamy added the bug Something isn't working label Jun 6, 2026
@olamy olamy added this to the 3.6.0-M2 milestone Jun 6, 2026
@olamy olamy merged commit e6c3851 into apache:master Jun 6, 2026
14 checks passed
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.

2 participants