{"record":{"id":"9881138b0f1a509b","repo":"java-native-access/jna","slug":"ret","errorCode":"ret","errorMessage":"Move to trash failed: <pFrom>: <message>","messagePattern":"Move to trash failed: <pFrom>: <message>","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/W32FileUtils.java","lineNumber":51,"sourceCode":"    @Override\n    public boolean hasTrash() {\n        return true;\n    }\n\n    @Override\n    public void moveToTrash(File... files) throws IOException {\n        Shell32 shell = Shell32.INSTANCE;\n        ShellAPI.SHFILEOPSTRUCT fileop = new ShellAPI.SHFILEOPSTRUCT();\n        fileop.wFunc = ShellAPI.FO_DELETE;\n        String[] paths = new String[files.length];\n        for (int i=0;i < paths.length;i++) {\n            paths[i] = files[i].getAbsolutePath();\n        }\n        fileop.pFrom = fileop.encodePaths(paths);\n        fileop.fFlags = ShellAPI.FOF_ALLOWUNDO|ShellAPI.FOF_NO_UI;\n        int ret = shell.SHFileOperation(fileop);\n        if (ret != 0) {\n            throw new IOException(\"Move to trash failed: \" + fileop.pFrom + \": \" +\n                                  Kernel32Util.formatMessageFromLastErrorCode(ret));\n        }\n        if (fileop.fAnyOperationsAborted) {\n            throw new IOException(\"Move to trash aborted\");\n        }\n    }\n}\n","sourceCodeStart":33,"sourceCodeEnd":59,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/W32FileUtils.java#L33-L59","documentation":"W32FileUtils.moveToTrash uses the Win32 SHFileOperation with FOFF_ALLOWUNDO|FOF_NO_UI to send files to the Recycle Bin. If SHFileOperation returns a non-zero code, an IOException with the source path list and the formatted error message is thrown; the operation did not complete.","triggerScenarios":"SHFileOperation returns an error code such as DE_INVALIDFILES (invalid/relative path), DE_ROOTDIR (attempting to trash a drive root), DE_FLDDESTEXISTS, or access-denied style codes; passing paths that are not fully absolute canonical paths.","commonSituations":"Trying to move a drive root or special/system files to trash; files locked by another process; paths containing wildcards or non-canonical forms; permission issues on the containing directory.","solutions":["Ensure all paths passed are absolute and canonical (File.getCanonicalFile().getAbsolutePath())","Exclude untrashable targets (drive roots, system files) before calling moveToTrash","Decode the Win32 code in the message and handle it (e.g. unlock file, elevate permissions)","Fall back to permanent delete (or skip) when recycling is impossible"],"exampleFix":"// before\nFileUtils.moveToTrash(new File(\"relative/path.txt\"));\n// after\nFile f = new File(\"relative/path.txt\").getCanonicalFile();\nif (!f.getParent().equals(FileSystemView.getFileSystemView()...)) {\n    FileUtils.moveToTrash(f);\n}","handlingStrategy":"try-catch","validationCode":"for (File f : files) {\n    File c = f.getCanonicalFile();\n    if (!c.isAbsolute() || c.getParent() == null) {\n        throw new IllegalArgumentException(\"Not trashable: \" + f);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    FileUtils.moveToTrash(files);\n} catch (IOException e) {\n    // parse error code; decide to skip, retry, or permanent delete\n}","preventionTips":["Always pass canonical absolute paths","Never attempt to trash drive roots or in-use system files","Handle locked-file and access-denied codes explicitly"],"tags":["win32","recycle-bin","shfileoperation"],"backgroundTag":"file-delete-failed","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}