scch-michael-pfeiffer opened a new issue, #3349:
URL: https://github.com/apache/maven-surefire/issues/3349
### Affected version
3.5.5
### Bug description
### 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
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.5</version>
<configuration>
<workingDirectory>${project.basedir}</workingDirectory>
<tempDir>${project.build.directory}/surefire-tmp</tempDir>
<argLine>-disableassertions</argLine>
</configuration>
</plugin>
```
### 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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]