{"record":{"id":"8cd543d84a1aac80","repo":"jenkinsci/jenkins","slug":"failed-to-obtain-file-from-path-dir","errorCode":null,"errorMessage":"Failed to obtain file from path ${dir}","messagePattern":"Failed to obtain file from path (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"critical","filePath":"core/src/main/java/hudson/FilePath.java","lineNumber":1744,"sourceCode":"        }\n\n            private static final long serialVersionUID = 1L;\n\n            @Override\n            public String invoke(File dir, VirtualChannel channel) throws IOException {\n\n                Path tempPath;\n                final boolean isPosix = FileSystems.getDefault().supportedFileAttributeViews().contains(\"posix\");\n\n                if (isPosix) {\n                    tempPath = Files.createTempDirectory(Util.fileToPath(dir), name,\n                            PosixFilePermissions.asFileAttribute(EnumSet.allOf(PosixFilePermission.class)));\n                } else {\n                    tempPath = Files.createTempDirectory(Util.fileToPath(dir), name);\n                }\n\n                if (tempPath.toFile() == null) {\n                    throw new IOException(\"Failed to obtain file from path \" + dir);\n                }\n                return tempPath.toFile().getName();\n            }\n    }\n\n    /**\n     * Deletes this file.\n     * @return true, for a modicum of compatibility\n     * @throws IOException if it exists but could not be successfully deleted\n     */\n    public boolean delete() throws IOException, InterruptedException {\n        act(new Delete());\n        return true;\n    }\n\n    private static class Delete extends MasterToSlaveFileCallable<Void> {\n        private static final long serialVersionUID = 1L;\n","sourceCodeStart":1726,"sourceCodeEnd":1762,"githubUrl":"https://github.com/jenkinsci/jenkins/blob/2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc/core/src/main/java/hudson/FilePath.java#L1726-L1762","documentation":"Thrown after Files.createTempDirectory succeeds but the resulting Path's toFile() returns null (which is technically impossible per the Java spec for valid Path objects backed by the default filesystem). The check is a defensive/dead-code guard — if you hit this, it indicates a custom FileSystem provider is returning a Path whose toFile() contract is violated, or memory/filesystem corruption. In practice this exception is unreachable under normal JRE usage.","triggerScenarios":"Calling FilePath.createTempDir() variants that delegate to Files.createTempDirectory on a system where the default FileSystem provider does not map to java.io.File. Only reachable if a custom FileSystem is registered as the default and returns non-file-backed Paths.","commonSituations":"Effectively never hit on standard JVM/JDK installations. Theoretical: running inside a test harness or container that replaces the default FileSystem provider, or a Jimfs/in-memory filesystem that doesn't implement toFile().","solutions":["Verify no custom FileSystem provider is being injected via -Djava.nio.file.spi.DefaultFileSystemProvider or META-INF services.","If using an in-memory filesystem (e.g., Jimfs), switch FilePath operations to a real temp directory backed by the OS filesystem.","Treat this as a JVM/filesystem bug — report the provider implementation that returns null from Path.toFile()."],"exampleFix":"// The guard is dead code; if hit, the root cause is the FileSystem provider.\n// No application-level fix. Verify the default provider:\nSystem.err.println(FileSystems.getDefault().provider().getClass());","handlingStrategy":"try-catch","validationCode":"// Unreachable in practice; verify the default FileSystem provider\nif (!FileSystems.getDefault().provider().getClass().getName().contains(\"sun\")) {\n    LOGGER.warning(\"Non-standard default FileSystem provider detected; FilePath temp dir creation may fail.\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    String tmpName = filePath.createTempDir(prefix);\n} catch (IOException e) {\n    if (e.getMessage().contains(\"Failed to obtain file from path\")) {\n        // Investigate FileSystem provider; this should not happen on standard JVMs\n        throw new IllegalStateException(\"Filesystem provider returned null Path.toFile()\", e);\n    }\n    throw e;\n}","preventionTips":["Do not register custom DefaultFileSystemProvider implementations that return non-file-backed Paths.","Avoid using in-memory filesystems (Jimfs) for FilePath operations that rely on java.io.File."],"tags":["filesystem","dead-code","filepath","temp-directory"],"backgroundTag":null,"analyzedSha":"2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc","analyzedAt":"2026-08-14T07:07:15.274Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}