java-native-access/jna · error · IOException

No trash location found (define fileutils.trash to be the pa

Error message

No trash location found (define fileutils.trash to be the path to the trash)

What it means

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.

Source

Thrown at contrib/platform/src/com/sun/jna/platform/FileUtils.java:105

                    }
                }
            }
            return trash;
        }

        @Override
        public boolean hasTrash() {
            return getTrashDirectory().exists();
        }

        /** 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

  1. Set -Dfileutils.trash=/path/to/trash to an existing writable directory
  2. Create the trash directory (e.g. ~/.local/share/Trash/files) before calling moveToTrash
  3. Check getTrashDirectory().exists() beforehand and fall back to plain deletion

Example fix

// before
FileUtils.getInstance().moveToTrash(file);
// after
File trash = new File(System.getProperty("user.home"), ".local/share/Trash/files");
if (!trash.exists()) trash.mkdirs();
System.setProperty("fileutils.trash", trash.getAbsolutePath());
FileUtils.getInstance().moveToTrash(file);
Defensive patterns

Strategy: try-catch

Validate before calling

File trash = getTrashDirectory();
if (trash == null || !trash.exists()) {
    System.setProperty("fileutils.trash", "/home/user/.local/share/Trash/files");
}

Try / catch

try {
    FileUtils.getInstance().moveToTrash(files);
} catch (IOException e) {
    logger.error("Trash unavailable: " + e.getMessage());
}

Prevention

When it happens

Trigger: Calling moveToTrash(...) with no trash directory available: fileutils.trash system property unset/invalid, no XDG trash, and getTrashDirectory() returning a non-existent path.

Common situations: 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.

Related errors


AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12). Data as JSON: /api/errors/773242c5567cd34e. Report an issue: GitHub.