java-native-access/jna · error · IOException
The following files could not be trashed: " + failed
Error message
The following files could not be trashed: " + failed
What it means
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.
Source
Thrown at contrib/platform/src/com/sun/jna/platform/FileUtils.java:116
/** The default implementation attempts to move the file to
* the desktop "Trash" folder.
*/
@Override
public void moveToTrash(File... files) throws IOException {
File trash = getTrashDirectory();
if (!trash.exists()) {
throw new IOException("No trash location found (define fileutils.trash to be the path to the trash)");
}
List<File> failed = new ArrayList<>();
for (int i=0;i < files.length;i++) {
File src = files[i];
File target = new File(trash, src.getName());
if (!src.renameTo(target)) {
failed.add(src);
}
}
if (failed.size() > 0) {
throw new IOException("The following files could not be trashed: " + failed);
}
}
}
}
View on GitHub (pinned to d036ad9781)
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
Example fix
// before
FileUtils.getInstance().moveToTrash(files);
// after
try {
FileUtils.getInstance().moveToTrash(files);
} catch (IOException e) {
for (File f : files) {
if (f.renameTo(new File(trashDir, f.getName()))) f.delete();
}
} Defensive patterns
Strategy: try-catch
Validate before calling
for (File f : files) {
if (!f.canRead() || !f.canWrite()) throw new IOException("Cannot move " + f);
} Try / catch
try {
FileUtils.getInstance().moveToTrash(files);
} catch (IOException e) {
// retry via copy+delete for cross-filesystem failures
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- No trash location found (define fileutils.trash to be the pa
- FileMonitor not implemented for " + os
- KeyboardUtils requires a keyboard
- No support (yet) for " + System.getProperty("os.name")
- Can't open X Display
AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12).
Data as JSON: /api/errors/a4ff4dcaa1d42d98.
Report an issue: GitHub.