OtterMind/Chat2DB · warning · IllegalArgumentException
Selected path is not a directory
Error message
Selected path is not a directory
What it means
Thrown by SqlDirectoryTreeStore.createRoot() when the user-selected path resolves (via toRealPath, which follows symlinks) to something that is not a directory. The method first calls Paths.get(rootPath).toRealPath() which would throw NoSuchFileException (IOException) for non-existent paths, so this IllegalArgumentException fires specifically when the path exists but is a regular file or special file — the user picked a file instead of a folder.
Source
Thrown at chat2db-community-server/chat2db-community-jcef/src/main/java/ai/chat2db/community/jcef/handler/biz/SqlDirectoryTreeStore.java:44
private static final Set<String> SUPPORTED_TEXT_EXTENSIONS = Set.of(
"sql", "txt", "md", "markdown",
"json", "jsonl", "yaml", "yml",
"csv", "tsv", "xml", "log",
"env", "ini", "conf", "config",
"properties", "toml");
private static final Set<String> SUPPORTED_IMAGE_EXTENSIONS = Set.of(
"png", "jpg", "jpeg", "gif", "webp", "bmp", "ico", "avif");
private static final Set<String> SUPPORTED_PREVIEW_EXTENSIONS = Set.of("pdf");
private static final long MAX_PREVIEW_BYTES = 50L * 1024L * 1024L;
private static final ConcurrentMap<String, Path> ROOTS = new ConcurrentHashMap<>();
private SqlDirectoryTreeStore() {
}
static Map<String, Object> createRoot(String rootPath) throws IOException {
Path root = Paths.get(rootPath).toRealPath();
if (!Files.isDirectory(root, LinkOption.NOFOLLOW_LINKS)) {
throw new IllegalArgumentException("Selected path is not a directory");
}
String rootToken = UUID.randomUUID().toString();
ROOTS.put(rootToken, root);
Map<String, Object> rootNode = new HashMap<>();
rootNode.put("key", rootToken + ":");
rootNode.put("rootToken", rootToken);
rootNode.put("rootPath", root.toString());
rootNode.put("name", getDisplayName(root));
rootNode.put("path", root.toString());
rootNode.put("relativePath", "");
rootNode.put("type", "directory");
rootNode.put("disabled", false);
rootNode.put("sqlFile", false);
rootNode.put("textFile", false);
rootNode.put("previewFile", false);
rootNode.put("hasChildren", true);View on GitHub (pinned to 5ee1e990e7)
Solutions
- In the frontend, ensure the directory picker (JFileChooser with DIRECTORIES_ONLY) or path input restricts selection to directories
- Validate on the frontend that the selected path is a directory before sending the open-sql-directory request
- If using a file chooser, set it to DIRECTORIES_ONLY mode so the user cannot select a file
Example fix
// before: file chooser allows file selection JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); // after: restrict to directories only JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
Defensive patterns
Strategy: validation
Validate before calling
// Before calling createRoot, validate the path is a directory
Path candidate = Paths.get(rootPath);
if (!Files.isDirectory(candidate)) {
throw new IllegalArgumentException("Path must be a directory: " + rootPath);
}
SqlDirectoryTreeStore.createRoot(rootPath); Try / catch
try {
Map<String, Object> root = SqlDirectoryTreeStore.createRoot(path);
ResponseBuilder.buildSuccessJcef(Map.of("data", root), callback);
} catch (IllegalArgumentException e) {
callback.failure(400, e.getMessage()); // Use 400, not 500, for validation errors
} Prevention
- Use JFileChooser with DIRECTORIES_ONLY mode so users cannot select files
- Validate the path is a directory on the frontend before sending the request
- Return HTTP 400 (not 500) for validation errors so the frontend can distinguish user errors from server errors
When it happens
Trigger: Invoked via the open-sql-directory or select-sql-directory JCEF action when the 'path' field in the request JSON points to a file (e.g., a .sql file) rather than a directory. The filechooser or manual path entry selected a file.
Common situations: User picks a .sql file in the directory chooser instead of its parent folder; frontend sends a file path from a tree node click instead of a directory path; the path was correct at selection time but a file was created at that location by another process.
Related errors
- File or directory already exists
- Selected path is not available
- Unsupported SQL directory child type
- Selected SQL directory root cannot be renamed
- Selected SQL directory root cannot be deleted
AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14).
Data as JSON: /api/errors/a71f5d23aa862b8d.
Report an issue: GitHub.