This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-mvnd.git


The following commit(s) were added to refs/heads/master by this push:
     new d1ad05d3 Change the working directory on the JetBrains Runtime too 
(#1490)
d1ad05d3 is described below

commit d1ad05d31c902aaa74534d65b5281a6c16432906
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.
---
 .../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 9dc0148c..dedd2bc6 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();

Reply via email to