This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch mvnd-1.x
in repository https://gitbox.apache.org/repos/asf/maven-mvnd.git
The following commit(s) were added to refs/heads/mvnd-1.x by this push:
new 798b48c1 Change the working directory on the JetBrains Runtime too
(#1490)
798b48c1 is described below
commit 798b48c1904403f528bb6e076f0bd3e6b0a8d8c6
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Mon Oct 26 01:09:20 2026 +0100
Change the working directory on the JetBrains Runtime too (#1490)
JBR puts java.io.IoOverNioFileSystem behind java.io.File, which keeps
the platform file system in a field instead of having userDir itself.
The NoSuchFieldException also aborted chDir before it moved the NIO
default directory, so relative paths kept the daemon's old directory.
(cherry picked from commit 1b9f65cd56b307187580bfde2ffe2c796b663858)
---
.../java/org/mvndaemon/mvnd/cli/EnvHelper.java | 36 +++++++++++++++++++---
1 file changed, 32 insertions(+), 4 deletions(-)
diff --git a/daemon/src/main/java/org/mvndaemon/mvnd/cli/EnvHelper.java
b/daemon/src/main/java/org/mvndaemon/mvnd/cli/EnvHelper.java
index e0e6aa24..50a1df4a 100644
--- a/daemon/src/main/java/org/mvndaemon/mvnd/cli/EnvHelper.java
+++ b/daemon/src/main/java/org/mvndaemon/mvnd/cli/EnvHelper.java
@@ -20,6 +20,7 @@ package org.mvndaemon.mvnd.cli;
import java.io.IOException;
import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
import java.nio.charset.Charset;
import java.nio.file.FileSystems;
import java.nio.file.Path;
@@ -118,10 +119,7 @@ public class EnvHelper {
if (JavaVersion.getJavaSpec() >= 11.0) {
Field fsField =
fileClass.getDeclaredField(JavaVersion.getJavaSpec() >= 21.0 ? "FS" : "fs");
fsField.setAccessible(true);
- Object fs = fsField.get(null);
- Field userDirField = fs.getClass().getDeclaredField("userDir");
- userDirField.setAccessible(true);
- userDirField.set(fs, workingDir);
+ setUserDir(fsField.get(null), workingDir);
}
// change current dir for the java.nio.Path class
Object fs = FileSystems.getDefault();
@@ -147,6 +145,36 @@ public class EnvHelper {
}
}
+ /**
+ * Sets {@code userDir} on the {@code java.io.FileSystem} behind {@link
java.io.File}. The JetBrains Runtime
+ * wraps the platform file system in {@code java.io.IoOverNioFileSystem},
which keeps it in a field of its own.
+ */
+ private static void setUserDir(Object fs, String workingDir) throws
ReflectiveOperationException {
+ Class<?> fileSystemClass = Class.forName("java.io.FileSystem");
+ for (Class<?> c = fs.getClass(); c != null && c != Object.class; c =
c.getSuperclass()) {
+ for (Field field : c.getDeclaredFields()) {
+ if ("userDir".equals(field.getName())) {
+ field.setAccessible(true);
+ field.set(fs, workingDir);
+ return;
+ }
+ }
+ }
+ for (Class<?> c = fs.getClass(); c != null && c != Object.class; c =
c.getSuperclass()) {
+ for (Field field : c.getDeclaredFields()) {
+ if (fileSystemClass.isAssignableFrom(field.getType()) &&
!Modifier.isStatic(field.getModifiers())) {
+ field.setAccessible(true);
+ Object delegate = field.get(fs);
+ if (delegate != null && delegate != fs) {
+ setUserDir(delegate, workingDir);
+ return;
+ }
+ }
+ }
+ }
+ throw new NoSuchFieldException("userDir in " +
fs.getClass().getName());
+ }
+
@SuppressWarnings("unchecked")
static void setEnv(Map<String, String> newenv) throws Exception {
Map<String, String> env = System.getenv();