{"record":{"id":"43691f0983a36522","repo":"pentaho/pentaho-kettle","slug":"illegal-attempt-to-create-directory-under-a-file","errorCode":null,"errorMessage":"Illegal attempt to create directory under a file","messagePattern":"Illegal attempt to create directory under a file","errorType":"exception","errorClass":"InvalidFileTypeException","httpStatus":null,"severity":"error","filePath":"plugins/file-open-save-new/core/src/main/java/org/pentaho/di/plugins/fileopensave/providers/local/LocalFileProvider.java","lineNumber":501,"sourceCode":"    }\n    return LocalDirectory.create( Utils.getParent( file.getParent(), FileSystems.getDefault().getSeparator() ),\n            Paths.get( file.getParent() ) );\n  }\n\n  public void clearProviderCache() {\n    //Any local caches that this provider might use should be cleared here.\n  }\n\n  //Should do nothing if the directory already exists, or create any directories that do not exist\n  @Override\n  public LocalFile createDirectory( Bowl bowl, String parentPath, LocalFile file, String newFolderName )\n    throws FileException {\n    LocalDirectory newLocalDirectory;\n    if ( file instanceof Directory ) {\n        newLocalDirectory = LocalDirectory.create( parentPath,\n          Paths.get( file.getPath() + FileSystems.getDefault().getSeparator() + newFolderName ) );\n    } else {\n      throw new InvalidFileTypeException( \"Illegal attempt to create directory under a file\" );\n    }\n    try {\n      return this.add( bowl, newLocalDirectory, null );\n    } catch ( FileExistsException e ) {\n      //The file already exists.  Suppress the error\n    }\n    return newLocalDirectory;\n  }\n\n  @Override\n  public LocalFile getFile( Bowl bowl, LocalFile file, VariableSpace space ) {\n     Paths.get( file.getPath() );\n    return null;\n  }\n\n  public class LocalFileVisitor extends SimpleFileVisitor<Path> {\n    private final OverwriteStatus overwriteStatus;\n    private Map<Path, Path> folderTransversedMap = new HashMap<>();","sourceCodeStart":483,"sourceCodeEnd":519,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/file-open-save-new/core/src/main/java/org/pentaho/di/plugins/fileopensave/providers/local/LocalFileProvider.java#L483-L519","documentation":"LocalFileProvider.createDirectory throws InvalidFileTypeException when the requested parent 'file' is not a Directory instance — i.e. an attempt to create a subfolder underneath a regular file. The provider only supports nesting directories under directories.","triggerScenarios":"Calling createDirectory with a LocalFile (non-directory) as parent, e.g. stale UI tree state or a caller passing the wrong node after the filesystem changed on disk.","commonSituations":"Folder created between listing and the create call (parent is now a file); UI passing the selected file instead of the selected folder; provider misuse from custom code.","solutions":["Verify the parent is a directory before calling createDirectory","Refresh the file tree and retry with the correct parent node","Catch InvalidFileTypeException and surface 'parent must be a folder' to the user"],"exampleFix":"// before\nprovider.createDirectory( bowl, someFile, \"newFolder\" );\n// after\nif ( someFile instanceof Directory ) { provider.createDirectory( bowl, someFile, \"newFolder\" ); }","handlingStrategy":"type-guard","validationCode":"if ( !( parent instanceof Directory ) ) {\n  throw new InvalidFileTypeException( \"Parent must be a directory\" );\n}","typeGuard":"boolean canMkdir( File f ) { return f instanceof Directory; }","tryCatchPattern":"try { provider.createDirectory( bowl, parent, name ); } catch ( InvalidFileTypeException e ) { showError( \"Selected parent is a file, choose a folder\" ); }","preventionTips":["Refresh the provider tree before mkdir operations","Restrict UI folder-creation actions to directory nodes","Handle FileExistsException separately (already suppressed by provider)"],"tags":["filesystem","local-provider","file-type","mkdir"],"backgroundTag":"path-is-not-a-directory","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}