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");
        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);
        }
        // change current dir for the java.nio.Path class
        Object fs = FileSystems.getDefault();
        Class<?> fsClass = fs.getClass();
        while (fsClass != Object.class) {
            if ("sun.nio.fs.UnixFileSystem".equals(fsClass.getName())) {
                Field defaultDirectoryField = fsClass.getDeclaredField("defaultDirectory");
                defaultDirectoryField.setAccessible(true);
                String encoding = System.getProperty("sun.jnu.encoding");
                Charset charset = encoding != null ? Charset.forName(encoding) : Charset.defaultCharset();
                defaultDirectoryField.set(fs, workingDir.getBytes(charset));
            } else if ("sun.nio.fs.WindowsFileSystem".equals(fsClass.getName())) {
                Field defaultDirectoryField = fsClass.getDeclaredField("defaultDirectory");
                Field defaultRootField = fsClass.getDeclaredField("defaultRoot");
                defaultDirectoryField.setAccessible(true);
                defaultRootField.setAccessible(true);
                Path wdir = Paths.get(workingDir);
                Path root = wdir.getRoot();
                defaultDirectoryField.set(fs, wdir.toString());
                defaultRootField.set(fs, root.toString());
            }
            fsClass = fsClass.getSuperclass();
        }
    }
@Test
    void testChdir() throws Exception {
        File d = new File("target/tstDir").getAbsoluteFile();
        d.mkdirs();
        EnvHelper.chDir(d.toString());
        assertEquals(new File(d, "test").getAbsolutePath(), new File("test").getAbsolutePath());
        assertEquals(
                d.toPath().resolve("test").toAbsolutePath().toString(),
                Paths.get("test").toAbsolutePath().toString());
    }