alibaba/nacos · warning · IllegalArgumentException

{} does not exist

Error message

{} does not exist

What it means

Thrown by IoUtils.cleanDirectory(File) when directory.exists() is false. cleanDirectory requires an existing directory; a missing path is treated as an illegal argument (IllegalArgumentException, not IOException). The message includes the path.

Source

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

            if (fileOrDir.exists()) {
                boolean isDeleteOk = fileOrDir.delete();
                if (!isDeleteOk) {
                    throw new IOException("delete fail");
                }
            }
        }
    }
    
    /**
     * 清理目录下的内容. 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) {

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Guard with directory.exists() / directory.isDirectory() before calling cleanDirectory.
  2. Create the directory first (mkdirs) if it may not exist, then clean.
  3. If the directory being absent is acceptable, skip cleaning rather than treating it as an error.

Example fix

// before
IoUtils.cleanDirectory(dir);

// after
if (dir.exists() && dir.isDirectory()) {
    IoUtils.cleanDirectory(dir);
}
Defensive patterns

Strategy: validation

Validate before calling

if (directory != null && directory.exists() && directory.isDirectory()) {
    IoUtils.cleanDirectory(directory);
}

Prevention

When it happens

Trigger: Calling cleanDirectory on a path that has not been created yet, or that was already deleted/concurrently removed before the call.

Common situations: Startup ordering where the directory is cleaned before it is created; a previous delete removed it; a config path that was never initialized; race with another cleaner.

Related errors


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