{"record":{"id":"34d7c0677200bdd6","repo":"alibaba/nacos","slug":"is-not-a-directory","errorCode":null,"errorMessage":"{} is not a directory","messagePattern":"(.+?) is not a directory","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"common/src/main/java/com/alibaba/nacos/common/utils/IoUtils.java","lineNumber":257,"sourceCode":"            }\n        }\n    }\n    \n    /**\n     * 清理目录下的内容. Clean content under directory.\n     *\n     * @param directory directory\n     * @throws IOException io exception\n     */\n    public static void cleanDirectory(File directory) throws IOException {\n        if (!directory.exists()) {\n            String message = directory + \" does not exist\";\n            throw new IllegalArgumentException(message);\n        }\n        \n        if (!directory.isDirectory()) {\n            String message = directory + \" is not a directory\";\n            throw new IllegalArgumentException(message);\n        }\n        \n        File[] files = directory.listFiles();\n        // null if security restricted\n        if (files == null) {\n            throw new IOException(\"Failed to list contents of \" + directory);\n        }\n        \n        IOException exception = null;\n        for (File file : files) {\n            try {\n                delete(file);\n            } catch (IOException ioe) {\n                exception = ioe;\n            }\n        }\n        \n        if (null != exception) {","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/common/src/main/java/com/alibaba/nacos/common/utils/IoUtils.java#L239-L275","documentation":"Thrown by IoUtils.cleanDirectory(File) when the path exists but is not a directory (directory.isDirectory() is false). Passing a regular file to a directory-cleaning routine is an illegal argument; the message includes the path.","triggerScenarios":"Calling cleanDirectory on a File that points to a regular file (or a special file) rather than a directory.","commonSituations":"A path that was expected to be a directory but is actually a file (misconfiguration, a stale file created in place of the expected folder, a symlink to a file).","solutions":["Check isDirectory() before calling cleanDirectory.","Use IoUtils.delete(file) if you actually intend to delete a single file.","Validate the configured path type at startup."],"exampleFix":"// before\nIoUtils.cleanDirectory(path);\n\n// after\nif (path.isDirectory()) {\n    IoUtils.cleanDirectory(path);\n} else if (path.isFile()) {\n    IoUtils.delete(path);\n}","handlingStrategy":"validation","validationCode":"if (path != null && path.isDirectory()) {\n    IoUtils.cleanDirectory(path);\n} else if (path != null && path.isFile()) {\n    IoUtils.delete(path);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check isDirectory() before cleanDirectory.","Use IoUtils.delete for regular files.","Validate configured path types at startup."],"tags":["io","filesystem","validation","directory","type-mismatch"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}