{"record":{"id":"c91f53589842fb03","repo":"pentaho/pentaho-kettle","slug":"filealreadyexistsexception-file","errorCode":null,"errorMessage":"FileAlreadyExistsException(file)","messagePattern":"FileAlreadyExistsException\\(file\\)","errorType":"exception","errorClass":"FileAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"plugins/avro-format/core/src/main/java/org/pentaho/di/trans/steps/avro/output/PentahoAvroOutputFormat.java","lineNumber":116,"sourceCode":"      errors.append( \"\\n\" );\n      errors.append( date + \" - Please set the Avro Schema Record name.\" );\n    }\n    if ( !StringUtils.isEmpty( errors.toString() ) ) {\n      throw new Exception( errors.toString() );\n    }\n  }\n\n  @Override\n  public void setFields( List<? extends IAvroOutputField> fields ) throws Exception {\n    this.fields = fields;\n    schema = null;\n    schemaObjectNode = null;\n  }\n\n\n  @Override public void setOutputFile( String file, boolean override ) throws Exception {\n    if ( !override && KettleVFS.getInstance( bowl ).fileExists( file, variableSpace ) ) {\n      throw new FileAlreadyExistsException( file );\n    }\n\n    this.outputFilename = file;\n  }\n\n  @Override\n  public void setCompression( CodecFactory compression ) {\n    this.codecFactory = compression;\n  }\n\n  @Override\n  public void setNameSpace( String namespace ) {\n    this.nameSpace = namespace;\n    schema = null;\n    schemaObjectNode = null;\n  }\n\n  @Override","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/avro-format/core/src/main/java/org/pentaho/di/trans/steps/avro/output/PentahoAvroOutputFormat.java#L98-L134","documentation":"PentahoAvroOutputFormat.setOutputFile throws FileAlreadyExistsException when the requested output file already exists in the Kettle VFS and the caller did not pass override=true. This is a safety guard so Avro output runs do not silently overwrite existing data files.","triggerScenarios":"Calling setOutputFile(file, false) (or an equivalent step configuration with 'override existing file' unchecked) when KettleVFS.fileExists(file) returns true for the target path.","commonSituations":"Re-running a transformation that writes to a fixed filename without deleting the previous output; forgetting to enable the overwrite option in the Avro output step dialog; output path pointing at a file left over from a failed previous run.","solutions":["Delete or archive the existing file at the target path before running","Enable the override/overwrite option so setOutputFile is called with override=true","Use a dynamic filename (timestamps/variables) so each run gets a unique path","Catch FileAlreadyExistsException and prompt the user or route to a new file"],"exampleFix":"// before\nformat.setOutputFile( \"file:///data/out.avro\", false );\n// after\nif ( KettleVFS.getInstance( bowl ).fileExists( \"file:///data/out.avro\", variableSpace ) ) {\n  // delete or pick a new name, or explicitly allow overwrite\n}\nformat.setOutputFile( \"file:///data/out.avro\", true );","handlingStrategy":"validation","validationCode":"KettleVFS vfs = KettleVFS.getInstance( bowl );\nif ( !override && vfs.fileExists( outputPath, variableSpace ) ) {\n  outputPath = generateUniqueName( outputPath ); // or delete / prompt\n}\nformat.setOutputFile( outputPath, override );","typeGuard":null,"tryCatchPattern":"try {\n  format.setOutputFile( file, override );\n} catch ( FileAlreadyExistsException e ) {\n  // choose a new filename or delete the existing file, then retry\n}","preventionTips":["Check file existence with KettleVFS before configuring the output","Use timestamped/variable-based filenames for idempotent runs","Enable overwrite explicitly only when intended","Clean up output files from failed runs"],"tags":["avro","file-io","overwrite-guard"],"backgroundTag":"file-already-exists","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"}