oracle/graal · error · UnsupportedOperationException
Path not associated with default file system.
Error message
Path not associated with default file system.
What it means
Thrown by TrufflePath.toFile() when the path does not belong to FileSystems.getDefault(). Path.toFile() is specified to work only for default-filesystem paths; converting a Truffle file system path to java.io.File is impossible because File has no notion of other providers.
Source
Thrown at espresso/src/com.oracle.truffle.espresso.io/src/sun/nio/fs/TrufflePath.java:256
public Path resolveSibling(Path other) {
if (other == null) {
throw new NullPointerException();
}
Path parent = getParent();
return (parent == null) ? other : parent.resolve(other);
}
@Override
public Path resolveSibling(String other) {
return resolveSibling(getFileSystem().getPath(other));
}
@Override
public File toFile() {
if (getFileSystem() == FileSystems.getDefault()) {
return new File(toString());
} else {
throw new UnsupportedOperationException("Path not associated with " + "default file system.");
}
}
@Override
public WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events) throws IOException {
return register(watcher, events, new WatchEvent.Modifier[0]);
}
@Override
public Iterator<Path> iterator() {
List<String> components = Arrays.asList(getPathComponents());
return MapFilterIterator.map(components.iterator(), s -> new TrufflePath(getTruffleFileSystem(), s));
}
// region native methods
private native void init0(String path);
View on GitHub (pinned to a66e9ccd1d)
Solutions
- Open the file through NIO instead: Files.newInputStream(path), Files.newOutputStream(path), Files.readAllBytes(path)
- If a File object is unavoidable, copy the content to a default-filesystem temp file first
- Refactor library call sites from File to Path/InputStream parameters
Example fix
// before
File f = trufflePath.toFile();
try (InputStream in = new FileInputStream(f)) { ... }
// after
try (InputStream in = Files.newInputStream(trufflePath)) { ... } Defensive patterns
Strategy: type-guard
Validate before calling
if (path.getFileSystem() != FileSystems.getDefault()) {
// use Files.newInputStream(path) instead of path.toFile()
} Type guard
static boolean canConvertToFile(Path p) {
return p.getFileSystem() == FileSystems.getDefault();
} Try / catch
catch (UnsupportedOperationException e) { fall back to Files.newInputStream(path)/Files.copy(path, tmpFile); } Prevention
- Prefer NIO APIs (Files.*) over java.io.File conversions
- When accepting Path parameters in libraries, open via Files.newInputStream rather than path.toFile()
When it happens
Trigger: Calling trufflePath.toFile(), or legacy APIs that internally do path.toFile() (e.g. old File-based libraries, Scanner(File), FileInputStream constructed via toFile) on a path obtained from the Truffle file system.
Common situations: Migrating legacy java.io.File-based code to NIO inside an Espresso guest; passing guest TrufflePaths into libraries whose signatures accept Path but immediately convert to File.
Related errors
- link option: {}
- Path component is undefined
- Path component should be '/'
- Query component present
- Fragment component present
AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14).
Data as JSON: /api/errors/79ac1f26672ee597.
Report an issue: GitHub.