{"record":{"id":"af554253f7cc3cbb","repo":"pentaho/pentaho-kettle","slug":"sorry-can-not-rename-on-the-fly-while-copying-in-the-same","errorCode":null,"errorMessage":"Sorry, can not rename on the fly while copying in the same VFS Connection.","messagePattern":"Sorry, can not rename on the fly while copying in the same VFS Connection\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"plugins/file-open-save-new/core/src/main/java/org/pentaho/di/plugins/fileopensave/providers/vfs/OverwriteAwareFileSelector.java","lineNumber":91,"sourceCode":"    if ( fileInfo.getFile().equals( copyFrom ) ) {\n      // If the file being worked is the original source then we already answered the overwrite question before the\n      // copy started.  So if this file is a duplicate we already said to overwrite it, or we wouldn't be here.\n      overwriteStatus.setOverwriteMode( OverwriteStatus.OverwriteMode.OVERWRITE );\n    } else {\n      overwriteStatus.promptOverwriteIfNecessary( destinationFileObject.exists(), destinationFile, \"folder\",\n        new OverwriteStatus.OverwriteMode[] { OverwriteStatus.OverwriteMode.RENAME },\n        \"Note: rename is not available.\" );\n    }\n    if ( overwriteStatus.isCancel() ) {\n      // We have to throw an exception or it will keep going through the tree\n      throw new FileException( \"Aborted by user.\" );\n    }\n    if ( overwriteStatus.isSkip() ) {\n      return false;\n    }\n    if ( overwriteStatus.isRename() ) {\n      //should not happen\n      throw new IllegalArgumentException(\n        \"Sorry, can not rename on the fly while copying in the same VFS Connection.\" );\n    }\n    return true;\n  }\n\n  private String convertFileInfoToOutputFile( FileSelectInfo fileInfo ) {\n    String sourceFile = fileInfo.getFile().getName().toString();\n    if ( !sourceFile.startsWith( copyFrom.getName().toString() ) ) {\n      throw new IllegalArgumentException( \"The incoming file did not start with the source path\" );\n    }\n    return copyTo.getName().toString() + sourceFile.substring( copyFrom.getName().toString().length() );\n  }\n\n  /**\n   * Wrapper around {@link KettleVFSService#getFileObject(String, VariableSpace)}\n   * @param vfsPath\n   * @param space\n   * @return","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/file-open-save-new/core/src/main/java/org/pentaho/di/plugins/fileopensave/providers/vfs/OverwriteAwareFileSelector.java#L73-L109","documentation":"OverwriteAwareFileSelector implements an overwrite/skip/rename prompt flow while copying files through a VFS connection. When the user chooses 'Rename', the selector cannot honor it because renaming mid-copy on the same VFS connection is not supported, so it throws this IllegalArgumentException as an explicit unsupported-operation guard (the comment says 'should not happen').","triggerScenarios":"Called from includeFile or traverseDescendents when a file with a duplicate name is found and the stored OverwriteStatus has isRename()==true — i.e. a rename decision reached the same-connection copy path.","commonSituations":"Batch copy jobs over a single VFS connection where users answer 'Rename' to overwrite prompts; UI flows that set rename in OverwriteStatus for targets inside the same connection; programmatic use of the selector with pre-seeded rename statuses.","solutions":["Answer 'Overwrite' or 'Skip' instead of 'Rename' when the prompt appears during a same-VFS-connection copy","Copy via two distinct VFS connections (or a local temp staging path) so rename-on-copy is available","Rename the destination file before starting the copy so no duplicate prompt is raised","Fix the calling code to never seed OverwriteStatus.isRename() when source and target share one connection"],"exampleFix":"// before\nif ( overwriteStatus.isRename() ) {\n  throw new IllegalArgumentException(\n    \"Sorry, can not rename on the fly while copying in the same VFS Connection.\" );\n}\n// after\nif ( overwriteStatus.isRename() ) {\n  // rename the target first, then copy\n  FileObject dest = getFileObject( targetName + \".bak\" );\n  dest.copyFrom( source, new AllFileSelector() );\n  return true;\n}","handlingStrategy":"validation","validationCode":"if ( overwriteStatus != null && overwriteStatus.isRename() && sameVfsConnection( source, target ) ) {\n  throw new IllegalArgumentException( \"Rename is not supported when copying within the same VFS connection\" );\n}","typeGuard":"boolean renameAllowed = overwriteStatus != null && overwriteStatus.isRename() && !sameVfsConnection( source, target );","tryCatchPattern":null,"preventionTips":["Do not seed rename into OverwriteStatus for same-connection copies","Rename targets before initiating the copy","Use separate VFS connections or a staging directory when rename-on-copy is needed"],"tags":["vfs","unsupported-operation","file-copy"],"backgroundTag":"unsupported-operation","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"}