apache / apache/maven-surefire
Maven Surefire fails on Windows when tempDir is an absolute path
- Dominant language
- Java
- Stars
- 461
- Forks
- 588
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 19
Description
### Affected version
3.5.5
### Bug description
When an absolute path is specified for the `tempDir` configuration in the `maven-surefire-plugin`, unit tests fail to execute under Windows. It appears the plugin is passing the directory path incorrectly to the underlying file system API, leading to an `IllegalArgumentException`.
### Steps to Reproduce
Configure the plugin with an absolute path for `tempDir`, for example:
```xml
org.apache.maven.plugins
maven-surefire-plugin
3.5.5
${project.basedir}
${project.build.directory}/surefire-tmp
-disableassertions
```
### Observed Behavior
The build fails with the following error:
> `Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.5.5:test (default-test) on project TopSecretProject: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:3.5.5:test failed: Invalid prefix or suffix`
### Root Cause Analysis
The error originates from `Files.createTempDirectory()` in `AbstractSurefireMojo.java`.
In the current implementation:
```java
File createSurefireBootDirectoryInTemp() {
try {
return Files.createTempDirectory(getTempDir()).toFile();
} catch (IOException e) {
return createSurefireBootDirectoryInBuild();
}
}
```
The method `getTempDir()` returns a string representing the path. However, `Files.createTempDirectory(String prefix, FileAttribute... attrs)` expects a **prefix string** to create a directory *within* the default temporary-file directory. On Windows, if `getTempDir()` returns an absolute path (e.g., containing `:` or `\`), it is treated as an invalid prefix, triggering the `IllegalArgumentException`.
### Suggested Fix
The plugin should allow the usage of absolute paths for the temporary directory on Windows by ensuring the path is handled as a `Path` object rather than a prefix string, or by validating the string before passing it to the NIO API.
Contributor guide
Research direction
Start in AbstractSurefireMojo.java at createSurefireBootDirectoryInTemp() and trace how getTempDir() is passed to Files.createTempDirectory(). Reproduce the Maven Surefire failure on Windows with an absolute tempDir, then verify that the plugin accepts the path and unit tests execute successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100