java-native-access/jna · error · IOException
The following files could not be trashed
Error message
The following files could not be trashed: {failed} What it means
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.
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
Example fix
// before
FileUtils.getInstance().moveToTrash(file);
// after
try {
FileUtils.getInstance().moveToTrash(file);
} catch (IOException e) {
if (!file.delete()) {
throw e;
}
} Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check files
for (File f : files) {
if (!f.exists() || !f.canWrite()) throw new IOException("Cannot trash: " + f);
} Try / catch
try { FileUtils.getInstance().moveToTrash(files); } catch (IOException e) { logger.warn("Trash failed: {}", e.getMessage()); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- CFString conversion fails or the provided buffer is too…
- CFString maximum number of bytes exceeds LONG_MAX.
- err
- No trash location found (define fileutils.trash to be the…
- Output directory NOT sucessfully created to
AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12).
Data as JSON: /api/errors/65a9e6d97483acd5.
Report an issue: GitHub.
Appendix: source
Thrown at contrib/platform/src/com/sun/jna/platform/mac/MacFileUtils.java:88
@Override
public void moveToTrash(File... files) throws IOException {
List<String> failed = new ArrayList<>();
for (File src: files) {
FileManager.FSRef fsref = new FileManager.FSRef();
int status = FileManager.INSTANCE.FSPathMakeRefWithOptions(src.getAbsolutePath(),
FileManager.kFSPathMakeRefDoNotFollowLeafSymlink,
fsref, null);
if (status != 0) {
failed.add(src + " (FSRef: " + status + ")");
continue;
}
status = FileManager.INSTANCE.FSMoveObjectToTrashSync(fsref, null, 0);
if (status != 0) {
failed.add(src + " (" + status + ")");
}
}
if (failed.size() > 0) {
throw new IOException("The following files could not be trashed: " + failed);
}
}
}
View on GitHub (pinned to d036ad9781)