MyCATApache/Mycat-Server · error · IOException
Failed to list files for dir:
Error message
Failed to list files for dir:
What it means
listFilesSafely is JavaUtils' internal helper used by deleteRecursively to enumerate a directory's children. It throws IOException when File.listFiles() returns null, which means the path is not a readable directory (e.g. permission denied or an I/O error) even though it exists.
Solutions
- Verify the path is a directory with read+execute permission before recursing (file.isDirectory() && file.canRead()).
- Fix permissions (chmod / chown) on the offending directory reported in the message.
- Check whether the path is a symlink or special file and resolve/handle it before deletion.
Example fix
// before
JavaUtils.deleteRecursively(dir);
// after
if (dir.isDirectory() && dir.canRead()) {
JavaUtils.deleteRecursively(dir);
} else {
throw new IOException("Not a readable directory: " + dir);
} Defensive patterns
Strategy: validation
Validate before calling
if (!dir.isDirectory() || !dir.canRead()) {
throw new IOException("Cannot list directory: " + dir);
} Try / catch
try {
JavaUtils.deleteRecursively(dir);
} catch (IOException e) {
logger.warn("Delete failed (list problem?): {}", e.getMessage());
} Prevention
- Verify the path is a real, readable directory (isDirectory + canRead) before recursive deletes.
- Resolve symlinks explicitly so you know what you are deleting.
- Keep directory permissions consistent across the tree you create.
When it happens
Trigger: deleteRecursively invoked on a path that exists but is not a readable directory, or on a directory whose permissions prevent listing (no read/execute bit), or a filesystem error.
Common situations: Deleting trees spanning directories with mixed ownership/permissions; the target path replaced by a symlink or special file; NFS/permissions issues where exists() is true but listFiles() fails.
Related errors
- Failed to create local dir in $newDir.
- Failed to delete:
- Mkdirs failed to create
- error while calling spill() on
- error while calling spill() on
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/0cdbdf7f921127ac.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/memory/unsafe/utils/JavaUtils.java:96
}
}
if (savedIOException != null) {
throw savedIOException;
}
}
boolean deleted = file.delete();
// Delete can also fail if the file simply did not exist.
if (!deleted && file.exists()) {
throw new IOException("Failed to delete: " + file.getAbsolutePath());
}
}
private static File[] listFilesSafely(File file) throws IOException {
if (file.exists()) {
File[] files = file.listFiles();
if (files == null) {
throw new IOException("Failed to list files for dir: " + file);
}
return files;
} else {
return new File[0];
}
}
private static boolean isSymlink(File file) throws IOException {
Preconditions.checkNotNull(file);
File fileInCanonicalDir = null;
if (file.getParent() == null) {
fileInCanonicalDir = file;
} else {
fileInCanonicalDir = new File(file.getParentFile().getCanonicalFile(), file.getName());
}
return !fileInCanonicalDir.getCanonicalFile().equals(fileInCanonicalDir.getAbsoluteFile());
}
View on GitHub (pinned to 65f8d8beb7)