Graal: [native-image] new File(".") points to native-image's cwd

Created on 28 Dec 2019  路  2Comments  路  Source: oracle/graal

It seems that after the AOT compilation, new File(".") in my code points to /Users/bsideup/.native-image/machine-id-hostid-0/session-id-11bf2/server-id-13a9cc69f0211a6fd8aec094a69254d6de5e1cea1bfc68ee02c4ef1da82c52d4da8c85912863a846a7993e5c03a118421e5fa02ecd9e69e16df6cc1a76e30c48/. instead of the current workdir of the process.

Since Paths.get(".") works fine, I would assume this is a bug.

GraalVM version: 19.3.0.2 (Java 11 mode)

Most helpful comment

All 2 comments

@bsideup , could you please expand your example? Are you using new File(".") in the constructor or as a static field?

I would assume it depends on the implementation. Probably Paths#get will be evaulated lazy and new File(".").

Repo-Case:

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;

public class FileMain {
public static void main(String[] args) {
Test1 test1 = new Test1();
System.out.println(test1.f.getAbsoluteFile().toString());
Test2 test2 = new Test2();
System.out.println(test2.p.toAbsolutePath().toString());
}
}

final class Test1 {
final File f;

public Test1() {
f = new File(".");
}
}

final class Test2 {
final Path p;

public Test2() {
p = Paths.get(".");
}
}

Output
sergej@sergej-P50:~/Development/Development/SVMPlayground/build/native-image$ ./file
/home/sergej/.native-image/machine-id-4423649c809a40b1a1a0b62fc6d4493d/session-id-1e6e/server-id-b8cc22305cdc3bcda8fefb1dfbe49a1fda6358e17b3ece51b729b5040741545a3471339657dfd1cd65d79356639e0894878a2158f3efadc7135b9bb4d3497362/.
/home/sergej/Development/Development/SVMPlayground/build/native-image/.

with
arguments(
'--no-fallback',
'--enable-all-security-services',
'--initialize-at-run-time=com.example.runtime',
'--report-unsupported-elements-at-runtime'
)

Note:
System.out.println(test1.f.toPath().toAbsolutePath().toFile()); will result in the same result as from @bsideup desired.

I think the problem is here: File.

private static final FileSystem fs = DefaultFileSystem.getFileSystem();
Was this page helpful?
0 / 5 - 0 ratings