apache / apache/maven-surefire
[SUREFIRE-2142] user.dir is changed in forkCount=0
- Dominant language
- Java
- Stars
- 461
- Forks
- 588
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 19
Description
**[Ivan Iliev](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=iiliev2)** opened **[SUREFIRE-2142](https://issues.apache.org/jira/browse/SUREFIRE-2142?redirect=false)** and commented
When **not** forking the tests, the
```java
user.dir
```
system property is changed to the current [ ](https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#workingDirectory). This can have a fatal effect on code which reads files via for ex. FileInputStream.
For ex. in a multi module maven project like:
/root/f1/p1/p2/m1
/root/f2/m2
such that the reactor builds m2 -> m1, and m2 executes in forkCount=0, the user.dir will be set to /root/f2/m2, then any code in m1's build pipeline which tries to open a file(even with absolute path) via FileInputStream will fail.
See
```java
org.apache.maven.plugin.surefire.AbstractSurefireMojo#setupProperties ->
result.setProperty( "user.dir", getWorkingDirectory().getAbsolutePath() ); ->
org.apache.maven.plugin.surefire.AbstractSurefireMojo#executeProvider ->
if ( isNotForking() )
{
createCopyAndReplaceForkNumPlaceholder( effectiveProperties, 1 ).copyToSystemProperties();
...
}
```
---
**Affects:** 3.0.0-M5
Contributor guide
Research direction
Start in org.apache.maven.plugin.surefire.AbstractSurefireMojo, following setupProperties into executeProvider and the isNotForking path described in the issue. Reproduce a forkCount=0 multi-module build and inspect the resulting user.dir value; done means the reported FileInputStream failure no longer occurs when tests are not forked.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100