{"record":{"id":"a4ff4dcaa1d42d98","repo":"java-native-access/jna","slug":"the-following-files-could-not-be-trashed-failed","errorCode":null,"errorMessage":"The following files could not be trashed: \" + failed","messagePattern":"The following files could not be trashed: \" \\+ failed","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/FileUtils.java","lineNumber":116,"sourceCode":"        /** The default implementation attempts to move the file to\n         * the desktop \"Trash\" folder.\n         */\n        @Override\n        public void moveToTrash(File... files) throws IOException {\n            File trash = getTrashDirectory();\n            if (!trash.exists()) {\n                throw new IOException(\"No trash location found (define fileutils.trash to be the path to the trash)\");\n            }\n            List<File> failed = new ArrayList<>();\n            for (int i=0;i < files.length;i++) {\n                File src = files[i];\n                File target = new File(trash, src.getName());\n                if (!src.renameTo(target)) {\n                    failed.add(src);\n                }\n            }\n            if (failed.size() > 0) {\n                throw new IOException(\"The following files could not be trashed: \" + failed);\n            }\n        }\n    }\n}\n","sourceCodeStart":98,"sourceCodeEnd":121,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/FileUtils.java#L98-L121","documentation":"moveToTrash throws IOException listing the files whose rename into the trash directory failed. Rename failures typically mean permission problems, cross-filesystem moves, or a target name collision the OS refuses to overwrite.","triggerScenarios":"Calling moveToTrash(files...) where src.renameTo(target) returns false for one or more files — e.g. trash on a different filesystem, read-only source/target, or insufficient permissions.","commonSituations":"Moving files from /tmp into a trash under /home (different mount points, rename fails); files locked or owned by another user; trash directory not writable.","solutions":["Check logs/failed list — ensure the trash directory is on the same filesystem as the files","Fix permissions on source files and the trash directory","Manually copy-then-delete when rename fails across filesystems"],"exampleFix":"// before\nFileUtils.getInstance().moveToTrash(files);\n// after\ntry {\n    FileUtils.getInstance().moveToTrash(files);\n} catch (IOException e) {\n    for (File f : files) {\n        if (f.renameTo(new File(trashDir, f.getName()))) f.delete();\n    }\n}","handlingStrategy":"try-catch","validationCode":"for (File f : files) {\n    if (!f.canRead() || !f.canWrite()) throw new IOException(\"Cannot move \" + f);\n}","typeGuard":null,"tryCatchPattern":"try {\n    FileUtils.getInstance().moveToTrash(files);\n} catch (IOException e) {\n    // retry via copy+delete for cross-filesystem failures\n}","preventionTips":["Keep trash on the same filesystem as the files","Verify write permissions on source files and trash dir","Log which files fail and fall back to manual copy+delete"],"tags":["java","filesystem","rename","permissions"],"backgroundTag":"file-write-failed","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}