From 2db9e89f832991f574b88450c292158bcc611d5b Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 2 Jun 2021 16:56:22 +0200 Subject: [PATCH] Fix the environment update, fixes #422 --- .../org/apache/maven/cli/DaemonMavenCli.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java index d6460d55..b9f604b9 100644 --- a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java +++ b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java @@ -700,19 +700,26 @@ public class DaemonMavenCli { } } + private static float javaSpec = 0.0f; + protected static void chDir(String workingDir) throws Exception { CLibrary.chdir(workingDir); System.setProperty("user.dir", workingDir); // change current dir for the java.io.File class Class fileClass = Class.forName("java.io.File"); - Field fsField = fileClass.getDeclaredField("fs"); - fsField.setAccessible(true); - Object fs = fsField.get(null); - Field userDirField = fs.getClass().getDeclaredField("userDir"); - userDirField.setAccessible(true); - userDirField.set(fs, workingDir); + if (javaSpec <= 0.0f) { + javaSpec = Float.parseFloat(System.getProperty("java.specification.version")); + } + if (javaSpec >= 11.0) { + Field fsField = fileClass.getDeclaredField("fs"); + fsField.setAccessible(true); + Object fs = fsField.get(null); + Field userDirField = fs.getClass().getDeclaredField("userDir"); + userDirField.setAccessible(true); + userDirField.set(fs, workingDir); + } // change current dir for the java.nio.Path class - fs = FileSystems.getDefault(); + Object fs = FileSystems.getDefault(); Class fsClass = fs.getClass(); while (fsClass != Object.class) { if ("sun.nio.fs.UnixFileSystem".equals(fsClass.getName())) {