alibaba/nacos · warning · IllegalArgumentException

{} is not a directory

Error message

{} is not a directory

What it means

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.

Source

Thrown at common/src/main/java/com/alibaba/nacos/common/utils/IoUtils.java:257

            }
        }
    }
    
    /**
     * 清理目录下的内容. Clean content under directory.
     *
     * @param directory directory
     * @throws IOException io exception
     */
    public static void cleanDirectory(File directory) throws IOException {
        if (!directory.exists()) {
            String message = directory + " does not exist";
            throw new IllegalArgumentException(message);
        }
        
        if (!directory.isDirectory()) {
            String message = directory + " is not a directory";
            throw new IllegalArgumentException(message);
        }
        
        File[] files = directory.listFiles();
        // null if security restricted
        if (files == null) {
            throw new IOException("Failed to list contents of " + directory);
        }
        
        IOException exception = null;
        for (File file : files) {
            try {
                delete(file);
            } catch (IOException ioe) {
                exception = ioe;
            }
        }
        
        if (null != exception) {

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Check isDirectory() before calling cleanDirectory.
  2. Use IoUtils.delete(file) if you actually intend to delete a single file.
  3. Validate the configured path type at startup.

Example fix

// before
IoUtils.cleanDirectory(path);

// after
if (path.isDirectory()) {
    IoUtils.cleanDirectory(path);
} else if (path.isFile()) {
    IoUtils.delete(path);
}
Defensive patterns

Strategy: validation

Validate before calling

if (path != null && path.isDirectory()) {
    IoUtils.cleanDirectory(path);
} else if (path != null && path.isFile()) {
    IoUtils.delete(path);
}

Prevention

When it happens

Trigger: Calling cleanDirectory on a File that points to a regular file (or a special file) rather than a directory.

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

Related errors


AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14). Data as JSON: /api/errors/34d7c0677200bdd6. Report an issue: GitHub.