OtterMind/Chat2DB · warning · IllegalArgumentException

Selected SQL directory root cannot be renamed

Error message

Selected SQL directory root cannot be renamed

What it means

Thrown by SqlDirectoryTreeStore.renameChild() when the source path equals the root path. The root directory is managed as an opaque token and cannot be renamed through this API — renaming it would invalidate all relativePath references in the tree and break the rootToken contract.

Source

Thrown at chat2db-community-server/chat2db-community-jcef/src/main/java/ai/chat2db/community/jcef/handler/biz/SqlDirectoryTreeStore.java:173

        String name = normalizeFileName(rawName, "sql");
        Path realTarget = writeAvailableFile(root, parent, name, content == null ? "" : content);
        if (!realTarget.startsWith(root)) {
            throw new IllegalArgumentException("Path is outside of the selected SQL directory");
        }

        Map<String, Object> result = new HashMap<>();
        result.put("createdNode", toNode(rootToken, root, realTarget));
        result.put("children", listChildren(rootToken, parentRelativePath));
        return result;
    }

    static Map<String, Object> renameChild(String rootToken, String relativePath, String rawName)
            throws IOException {
        Path root = getRoot(rootToken);
        Path source = resolveInRoot(root, relativePath);
        if (source.equals(root)) {
            throw new IllegalArgumentException("Selected SQL directory root cannot be renamed");
        }
        if (Files.isSymbolicLink(source)) {
            throw new IllegalArgumentException("Symbolic links are not supported");
        }

        boolean file = Files.isRegularFile(source, LinkOption.NOFOLLOW_LINKS);
        boolean directory = Files.isDirectory(source, LinkOption.NOFOLLOW_LINKS);
        if (!file && !directory) {
            throw new IllegalArgumentException("Selected path is not available");
        }
        String sourceFileName = source.getFileName().toString();
        String fallbackExtension = file ? getFileExtension(sourceFileName) : "";
        String name = file ? normalizeExistingFileName(rawName, fallbackExtension)
                : normalizeDirectoryName(rawName);
        Path parent = source.getParent();
        Path target = parent.resolve(name).normalize();
        if (!target.startsWith(root)) {
            throw new IllegalArgumentException("Path is outside of the selected SQL directory");

View on GitHub (pinned to 5ee1e990e7)

Solutions

  1. On the frontend, disable rename for the root node (check if relativePath is empty or node is the root)
  2. Show the root node as non-renameable in the tree UI
  3. Handle the error response and inform the user that the root directory cannot be renamed

Example fix

// before: rename enabled on all nodes including root
function onRename(node, newName) {
  renameChild(node.rootToken, node.relativePath, newName);
}

// after: skip root node
function onRename(node, newName) {
  if (node.relativePath === '' || node.relativePath === ':') {
    showError('The root directory cannot be renamed');
    return;
  }
  renameChild(node.rootToken, node.relativePath, newName);
}
Defensive patterns

Strategy: validation

Validate before calling

// Before calling renameChild, verify the node is not the root
if (relativePath == null || relativePath.isEmpty()) {
    throw new IllegalArgumentException("Cannot rename the root directory");
}
SqlDirectoryTreeStore.renameChild(rootToken, relativePath, rawName);

Try / catch

try {
    Map<String, Object> result = SqlDirectoryTreeStore.renameChild(rootToken, relativePath, name);
    ResponseBuilder.buildSuccessJcef(Map.of("data", result), callback);
} catch (IllegalArgumentException e) {
    callback.failure(400, e.getMessage());
}

Prevention

When it happens

Trigger: Invoked via rename-sql-directory-child JCEF action when relativePath is empty or resolves to the root itself. The frontend sent a rename request for the root node, or the relativePath was computed incorrectly to match root.

Common situations: Frontend allows the user to enter rename mode on the root tree node; the relativePath is empty string '' (which resolves to root in resolveInRoot); a UI bug sends the root node to the rename action.

Related errors


AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14). Data as JSON: /api/errors/7bf05d7c8ca13e00. Report an issue: GitHub.