{"record":{"id":"be3478e2bfb9d221","repo":"alibaba/arthas","slug":"name-is-a-directory","errorCode":null,"errorMessage":"${name}: Is a directory","messagePattern":"(.+?): Is a directory","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/com/taobao/arthas/core/shell/command/internal/RedirectHandler.java","lineNumber":30,"sourceCode":" * 重定向处理类\n *\n * @author gehui 2017年7月27日 上午11:38:40\n * @author hengyunabc 2019-02-06\n */\npublic class RedirectHandler extends PlainTextHandler implements CloseFunction {\n    private PrintWriter out;\n\n    private File file;\n\n    public RedirectHandler() {\n\n    }\n\n    public RedirectHandler(String name, boolean append) throws IOException {\n        File file = new File(name);\n\n        if (file.isDirectory()) {\n            throw new IOException(name + \": Is a directory\");\n        }\n\n        if (!file.exists()) {\n            File parentFile = file.getParentFile();\n            if (parentFile != null) {\n                parentFile.mkdirs();\n            }\n        }\n        this.file = file;\n        out = new PrintWriter(new BufferedWriter(new FileWriter(file, append)));\n    }\n\n    @Override\n    public String apply(String data) {\n        data = super.apply(data);\n        if (out != null) {\n            out.write(data);\n            out.flush();","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/core/src/main/java/com/taobao/arthas/core/shell/command/internal/RedirectHandler.java#L12-L48","documentation":"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.","triggerScenarios":"Using output redirection in an Arthas shell command (e.g., 'thread > /tmp' or 'dashboard >> /var/log') where the target path is an existing directory.","commonSituations":"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.","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."],"exampleFix":"// before (in Arthas shell)\nthread > /tmp\n// after\nthread > /tmp/thread-dump.txt","handlingStrategy":"validation","validationCode":"// Before constructing RedirectHandler, check the target is not a directory\nFile f = new File(name);\nif (f.isDirectory()) {\n    throw new IOException(name + \": Is a directory — specify a file path\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    RedirectHandler handler = new RedirectHandler(name, append);\n} catch (IOException e) {\n    if (e.getMessage().endsWith(\": Is a directory\")) {\n        // redirect target is a directory — ask user for a file path\n    }\n}","preventionTips":["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."],"tags":["shell","redirect","filesystem","arthas"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}