{"record":{"id":"122faed5d98cc257","repo":"pentaho/pentaho-kettle","slug":"file-already-exists","errorCode":null,"errorMessage":"File already exists: ","messagePattern":"File already exists: ","errorType":"exception","errorClass":"ContentCreationException","httpStatus":null,"severity":"error","filePath":"plugins/pentaho-reporting/impl/src/main/java/org/pentaho/di/trans/steps/pentahoreporting/urlrepository/FileObjectContentLocation.java","lineNumber":160,"sourceCode":"   *\n   * @param name the name of the new entity.\n   * @return the newly created entity, never null.\n   * @throws ContentCreationException if the item could not be created.\n   */\n  public ContentItem createItem( final String name ) throws ContentCreationException {\n    String fileName = new File( name ).getName();\n    if ( RepositoryUtilities.isInvalidPathName( fileName ) ) {\n      throw new IllegalArgumentException( \"The name given is not valid.\" );\n    }\n    try {\n      final FileObject file = getBackend();\n      final FileObject child = file.resolveFile( fileName );\n      if ( child.exists() ) {\n        if ( child.getContent().getSize() == 0 ) {\n          // probably one of the temp files created by the pentaho-system\n          return new FileObjectContentItem( this, child );\n        }\n        throw new ContentCreationException( \"File already exists: \" + child );\n      }\n      try {\n        child.createFile();\n        return new FileObjectContentItem( this, child );\n      } catch ( IOException e ) {\n        throw new ContentCreationException( \"IOError while create\", e );\n      }\n    } catch ( FileSystemException e ) {\n      throw new RuntimeException( e );\n    }\n  }\n\n  /**\n   * Creates a new content location in the current location. This method must never return null. This method will fail\n   * if an entity with the same name exists in this location.\n   *\n   * @param name the name of the new entity.\n   * @return the newly created entity, never null.","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/pentaho-reporting/impl/src/main/java/org/pentaho/di/trans/steps/pentahoreporting/urlrepository/FileObjectContentLocation.java#L142-L178","documentation":"FileObjectContentLocation.createItem refuses to overwrite an existing non-empty file: after resolving the child, if it exists with size > 0 it throws ContentCreationException 'File already exists: <child>'. Zero-size files are treated as leftover temp files and reused.","triggerScenarios":"Calling createItem(fileName) when resolveFile(fileName) already exists and getContent().getSize() > 0.","commonSituations":"Re-running a Kettle transformation that writes a report to the same output file without deleting or versioning the previous one; two concurrent transformation runs writing the same report path.","solutions":["Delete the existing file before calling createItem.","Use a unique file name (timestamp/UUID) per run.","Catch ContentCreationException and fall back to overwriting via the existing ContentItem's OutputStream.","Clean up stale zero-byte temp files only if they block creation elsewhere."],"exampleFix":"// before\nContentItem item = location.createItem(\"report.prpt\");\n// after\nContentItem item;\ntry {\n  item = location.createItem(\"report.prpt\");\n} catch (ContentCreationException e) {\n  ContentItem existing = location.getEntry(\"report.prpt\");\n  existing.delete();\n  item = location.createItem(\"report.prpt\");\n}","handlingStrategy":"validation","validationCode":"FileObject child = ((FileObjectContentLocation) location).getBackend().resolveFile(fileName);\nboolean conflicts = child.exists(); // treat >0 size existing file as conflict","typeGuard":null,"tryCatchPattern":"try {\n  item = location.createItem(fileName);\n} catch (ContentCreationException e) {\n  if (e.getMessage().startsWith(\"File already exists\")) { /* delete or rename then retry */ }\n}","preventionTips":["Use unique output names per run (timestamp/UUID).","Delete or archive previous outputs before rerunning jobs.","Avoid concurrent runs writing to the same report path."],"tags":["vfs","content-repository","file-conflict"],"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"}