質問

The presence of an HKEY_CURRENT_USER\Software\Microsoft\Command Processor\Autorun causes a java test to fail. Github repo to test this out : https://github.com/ajorpheus/final-frontier

This is a follow-up question after this happened.

Summary : Apparently a registry hack which allows a command to be run every time the cmd prompt is opened, adversely affects the Java process.

To begin with I thought, that perhaps it was the fact that 'mvn clean test' actually resolves to 'mvn.bat clean test'. However, I tried extracting the java.exe command contained in the mvn.bat file and tried using that directly, but got the same issue.

Any thoughts about why this might be happening ?

Update

Value of the Autorun entry is : cd /d "c:\dev"

Error message is as follows:
java.lang.RuntimeException: Error writing to file: some-dir/target/generated-resources/stuff.xmlwith the following error: Couldn't create dir: some-dir\target\generated-resources at com.test.build.TestFileCreation.createDirectoryTest

Update2

As @NilsH suggested, I've confirmed that the current working directory in both the cases is the same.

Update3

Added a maven profile which sets maven-surefire-plugin's forkMode to never. This profile causes the test to pass irrespective of whether the registry hack is there or not.

役に立ちましたか?

解決

When the surfire plugin execute the test in a forked environment, it starts a new cmd process. For this environment the registry hack will set the working directory to "c:\dev" and the JVM is started from within.

parent.exists()

Resolves the path against the directory from which the JVM was started. Which means the test checks the presence of file "C:/dev/some-dir/target/generated-resources/stuff.xml".

parent.getAbsoluteFile().exists()

This checks the presence of the file with it's absolute name, the one you expected to check.

see also the EVALUATION comment for this filed JDK bug
4483097 : File returned by getAbsoluteFile() may not refer to the original file

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top