alibaba/arthas · error · IOException
${name}: Is a directory
Error message
${name}: Is a directory What it means
The Arthas shell redirect handler (for '>' and '>>' output redirection) refuses to open a path that is an existing directory, mirroring standard POSIX shell behavior. It throws IOException before attempting FileWriter creation, which would produce a more cryptic error.
Source
Thrown at core/src/main/java/com/taobao/arthas/core/shell/command/internal/RedirectHandler.java:30
* 重定向处理类
*
* @author gehui 2017年7月27日 上午11:38:40
* @author hengyunabc 2019-02-06
*/
public class RedirectHandler extends PlainTextHandler implements CloseFunction {
private PrintWriter out;
private File file;
public RedirectHandler() {
}
public RedirectHandler(String name, boolean append) throws IOException {
File file = new File(name);
if (file.isDirectory()) {
throw new IOException(name + ": Is a directory");
}
if (!file.exists()) {
File parentFile = file.getParentFile();
if (parentFile != null) {
parentFile.mkdirs();
}
}
this.file = file;
out = new PrintWriter(new BufferedWriter(new FileWriter(file, append)));
}
@Override
public String apply(String data) {
data = super.apply(data);
if (out != null) {
out.write(data);
out.flush();View on GitHub (pinned to 21cf2e9ba5)
Solutions
- Specify a file path, not a directory path.
- Append a filename to the directory (e.g., /tmp/output.txt instead of /tmp).
- Remove trailing slashes from the redirect target.
Example fix
// before (in Arthas shell) thread > /tmp // after thread > /tmp/thread-dump.txt
Defensive patterns
Strategy: validation
Validate before calling
// Before constructing RedirectHandler, check the target is not a directory
File f = new File(name);
if (f.isDirectory()) {
throw new IOException(name + ": Is a directory — specify a file path");
} Try / catch
try {
RedirectHandler handler = new RedirectHandler(name, append);
} catch (IOException e) {
if (e.getMessage().endsWith(": Is a directory")) {
// redirect target is a directory — ask user for a file path
}
} Prevention
- Always specify a file path (with a filename) when using output redirection in Arthas.
- Remove trailing slashes from redirect targets.
- Test the redirect path with File.isDirectory before use in automated scripts.
When it happens
Trigger: Using output redirection in an Arthas shell command (e.g., 'thread > /tmp' or 'dashboard >> /var/log') where the target path is an existing directory.
Common situations: User specifies a directory path instead of a file; trailing slash on the path; a directory name collides with the intended file name; the parent directory is given by mistake.
Related errors
- ${filePath}: Is a directory
- can not find arthas-core.jar under arthasHome: ${arthasHome}
- Failed to create directory within ${TEMP_DIR_ATTEMPTS} attem
- File '{}' exists but is a directory
- File '{}' cannot be written to
AI-assisted analysis of alibaba/arthas@21cf2e9ba5 (2026-08-14).
Data as JSON: /api/errors/be3478e2bfb9d221.
Report an issue: GitHub.