{"record":{"id":"773242c5567cd34e","repo":"java-native-access/jna","slug":"no-trash-location-found-define-fileutils-trash-to-be-the","errorCode":null,"errorMessage":"No trash location found (define fileutils.trash to be the path to the trash)","messagePattern":"No trash location found \\(define fileutils\\.trash to be the path to the trash\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/FileUtils.java","lineNumber":105,"sourceCode":"                    }\n                }\n            }\n            return trash;\n        }\n\n        @Override\n        public boolean hasTrash() {\n            return getTrashDirectory().exists();\n        }\n\n        /** 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":87,"sourceCodeEnd":121,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/FileUtils.java#L87-L121","documentation":"LinuxFileUtils.moveToTrash throws IOException when the configured trash directory (from the fileutils.trash system property or XDG lookup) does not exist, so files cannot be moved to it. The library requires a real trash path to relocate files into before deletion.","triggerScenarios":"Calling moveToTrash(...) with no trash directory available: fileutils.trash system property unset/invalid, no XDG trash, and getTrashDirectory() returning a non-existent path.","commonSituations":"Headless Linux servers or containers with no desktop trash (no ~/.local/share/Trash); running as a different user whose home has no Trash folder; typo'd fileutils.trash path.","solutions":["Set -Dfileutils.trash=/path/to/trash to an existing writable directory","Create the trash directory (e.g. ~/.local/share/Trash/files) before calling moveToTrash","Check getTrashDirectory().exists() beforehand and fall back to plain deletion"],"exampleFix":"// before\nFileUtils.getInstance().moveToTrash(file);\n// after\nFile trash = new File(System.getProperty(\"user.home\"), \".local/share/Trash/files\");\nif (!trash.exists()) trash.mkdirs();\nSystem.setProperty(\"fileutils.trash\", trash.getAbsolutePath());\nFileUtils.getInstance().moveToTrash(file);","handlingStrategy":"try-catch","validationCode":"File trash = getTrashDirectory();\nif (trash == null || !trash.exists()) {\n    System.setProperty(\"fileutils.trash\", \"/home/user/.local/share/Trash/files\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    FileUtils.getInstance().moveToTrash(files);\n} catch (IOException e) {\n    logger.error(\"Trash unavailable: \" + e.getMessage());\n}","preventionTips":["Ensure fileutils.trash points to an existing writable directory","Create XDG trash dirs in container/server images","Check trash existence before moving files"],"tags":["java","filesystem","trash","io"],"backgroundTag":"directory-not-found","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"}