{"record":{"id":"65a9e6d97483acd5","repo":"java-native-access/jna","slug":"the-following-files-could-not-be-trashed-failed-macfileutils","errorCode":null,"errorMessage":"The following files could not be trashed: {failed}","messagePattern":"The following files could not be trashed: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/mac/MacFileUtils.java","lineNumber":88,"sourceCode":"    @Override\n    public void moveToTrash(File... files) throws IOException {\n        List<String> failed = new ArrayList<>();\n        for (File src: files) {\n            FileManager.FSRef fsref = new FileManager.FSRef();\n            int status = FileManager.INSTANCE.FSPathMakeRefWithOptions(src.getAbsolutePath(),\n                                                                       FileManager.kFSPathMakeRefDoNotFollowLeafSymlink,\n                                                                       fsref, null);\n            if (status != 0) {\n                failed.add(src + \" (FSRef: \" + status + \")\");\n                continue;\n            }\n            status = FileManager.INSTANCE.FSMoveObjectToTrashSync(fsref, null, 0);\n            if (status != 0) {\n                failed.add(src + \" (\" + status + \")\");\n            }\n        }\n        if (failed.size() > 0) {\n            throw new IOException(\"The following files could not be trashed: \" + failed);\n        }\n    }\n}\n","sourceCodeStart":70,"sourceCodeEnd":92,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/mac/MacFileUtils.java#L70-L92","documentation":"MacFileUtils.moveToTrash() calls FSMoveObjectToTrashSync for each requested file and collects any that fail with their OSStatus code. If any file could not be moved to the Trash, an IOException listing every failed path with its status code is thrown.","triggerScenarios":"Calling FileUtils.moveToTrash(File...) on macOS when the Finder trash operation fails: nonexistent path, permission denied, file locked, network volume that does not support trashing, or a non-zero OSStatus returned by FSMoveObjectToTrashSync.","commonSituations":"Attempting to trash files on read-only or network-mounted volumes; files deleted concurrently by another process; sandboxed apps lacking Finder integration; paths with insufficient permissions.","solutions":["Check each file exists and is readable/writable before calling moveToTrash","Catch the IOException and inspect the included OSStatus codes to handle individual failures","Fall back to direct File.delete() for files that cannot be trashed"],"exampleFix":"// before\nFileUtils.getInstance().moveToTrash(file);\n// after\ntry {\n    FileUtils.getInstance().moveToTrash(file);\n} catch (IOException e) {\n    if (!file.delete()) {\n        throw e;\n    }\n}","handlingStrategy":"try-catch","validationCode":"// pre-check files\nfor (File f : files) {\n    if (!f.exists() || !f.canWrite()) throw new IOException(\"Cannot trash: \" + f);\n}","typeGuard":null,"tryCatchPattern":"try { FileUtils.getInstance().moveToTrash(files); } catch (IOException e) { logger.warn(\"Trash failed: {}\", e.getMessage()); }","preventionTips":["Check existence and writability before trashing","Skip trashing files on read-only/network volumes","Inspect the OSStatus codes included in the message to diagnose per-file failures"],"tags":["macos","file-io","trash","ioexception"],"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"}