{"record":{"id":"79ac1f26672ee597","repo":"oracle/graal","slug":"path-not-associated-with-default-file-system","errorCode":null,"errorMessage":"Path not associated with default file system.","messagePattern":"Path not associated with default file system\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"espresso/src/com.oracle.truffle.espresso.io/src/sun/nio/fs/TrufflePath.java","lineNumber":256,"sourceCode":"    public Path resolveSibling(Path other) {\n        if (other == null) {\n            throw new NullPointerException();\n        }\n        Path parent = getParent();\n        return (parent == null) ? other : parent.resolve(other);\n    }\n\n    @Override\n    public Path resolveSibling(String other) {\n        return resolveSibling(getFileSystem().getPath(other));\n    }\n\n    @Override\n    public File toFile() {\n        if (getFileSystem() == FileSystems.getDefault()) {\n            return new File(toString());\n        } else {\n            throw new UnsupportedOperationException(\"Path not associated with \" + \"default file system.\");\n        }\n    }\n\n    @Override\n    public WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events) throws IOException {\n        return register(watcher, events, new WatchEvent.Modifier[0]);\n    }\n\n    @Override\n    public Iterator<Path> iterator() {\n        List<String> components = Arrays.asList(getPathComponents());\n        return MapFilterIterator.map(components.iterator(), s -> new TrufflePath(getTruffleFileSystem(), s));\n    }\n\n    // region native methods\n\n    private native void init0(String path);\n","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/espresso/src/com.oracle.truffle.espresso.io/src/sun/nio/fs/TrufflePath.java#L238-L274","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nFile f = trufflePath.toFile();\ntry (InputStream in = new FileInputStream(f)) { ... }\n\n// after\ntry (InputStream in = Files.newInputStream(trufflePath)) { ... }","handlingStrategy":"type-guard","validationCode":"if (path.getFileSystem() != FileSystems.getDefault()) {\n    // use Files.newInputStream(path) instead of path.toFile()\n}","typeGuard":"static boolean canConvertToFile(Path p) {\n    return p.getFileSystem() == FileSystems.getDefault();\n}","tryCatchPattern":"catch (UnsupportedOperationException e) { fall back to Files.newInputStream(path)/Files.copy(path, tmpFile); }","preventionTips":["Prefer NIO APIs (Files.*) over java.io.File conversions","When accepting Path parameters in libraries, open via Files.newInputStream rather than path.toFile()"],"tags":["espresso","nio","java-io-interop","path","truffle"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}