openjdk/jdk · warning · IOException

Directory 'New folder' exists

Error message

Directory 'New folder' exists

What it means

IOException from ExampleFileSystemView.createNewFolder in the FileChooserDemo: the demo unconditionally names new folders 'New folder', so creating one fails if a file or directory with that name already exists in containingDir. It is a demo-simplification guard, not a general-purpose API.

Source

Thrown at src/demo/share/jfc/FileChooserDemo/ExampleFileSystemView.java:63


/**
 * This is a simple example that uses the FileSystemView class.
 * You can provide a superclass of the FileSystemView class with your own functionality.
 *
 * @author Pavel Porvatov
 */
public class ExampleFileSystemView extends FileSystemView {

    /**
     * Creates a new folder with the default name "New folder". This method is invoked
     * when the user presses the "New folder" button.
     */
    public File createNewFolder(File containingDir) throws IOException {
        File result = new File(containingDir, "New folder");

        if (result.exists()) {
            throw new IOException("Directory 'New folder' exists");
        }

        if (!result.mkdir()) {
            throw new IOException("Cannot create directory");
        }

        return result;
    }

    /**
     * Returns a list which appears in a drop-down list of the FileChooser component.
     * In this implementation only the home directory is returned.
     */
    @Override
    public File[] getRoots() {
        return new File[] { getHomeDirectory() };
    }

View on GitHub (pinned to 88dfb74bbe)

Solutions

  1. As a user of the demo: navigate to a directory without an existing 'New folder' or delete/rename the old one first.
  2. As a developer copying this code: generate a unique name before calling mkdir (see example fix).

Example fix

// before
File result = new File(containingDir, "New folder");

// after: pick a unique name
File result = new File(containingDir, "New folder");
int i = 2;
while (result.exists()) {
    result = new File(containingDir, "New folder (" + (i++) + ")");
}
Defensive patterns

Strategy: validation

Validate before calling

// check (and pick a unique name) before creating
File result = new File(containingDir, "New folder");
int n = 2;
while (result.exists()) result = new File(containingDir, "New folder (" + n++ + ")");

Try / catch

try {
    return fsv.createNewFolder(dir);
} catch (IOException e) {
    // name clash: propose a suffixed name to the user and retry once
    return new File(dir, "New folder " + System.currentTimeMillis());
}

Prevention

When it happens

Trigger: Clicking the 'New folder' button in the running FileChooserDemo twice, or opening a directory that already contains 'New folder'.

Common situations: Any real application copying this demo's FileSystemView implementation verbatim — real file managers need unique names ('New folder (2)', ...) which this demo deliberately omits.

Related errors


AI-assisted analysis of openjdk/jdk@88dfb74bbe (2026-08-14). Data as JSON: /api/errors/0084debe4b2d65e0. Report an issue: GitHub.