pentaho/pentaho-kettle · error · ContentCreationException

File already exists:

Error message

File already exists: 

What it means

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.

Solutions

  1. Delete the existing file before calling createItem.
  2. Use a unique file name (timestamp/UUID) per run.
  3. Catch ContentCreationException and fall back to overwriting via the existing ContentItem's OutputStream.
  4. Clean up stale zero-byte temp files only if they block creation elsewhere.

Example fix

// before
ContentItem item = location.createItem("report.prpt");
// after
ContentItem item;
try {
  item = location.createItem("report.prpt");
} catch (ContentCreationException e) {
  ContentItem existing = location.getEntry("report.prpt");
  existing.delete();
  item = location.createItem("report.prpt");
}
Defensive patterns

Strategy: validation

Validate before calling

FileObject child = ((FileObjectContentLocation) location).getBackend().resolveFile(fileName);
boolean conflicts = child.exists(); // treat >0 size existing file as conflict

Try / catch

try {
  item = location.createItem(fileName);
} catch (ContentCreationException e) {
  if (e.getMessage().startsWith("File already exists")) { /* delete or rename then retry */ }
}

Prevention

When it happens

Trigger: Calling createItem(fileName) when resolveFile(fileName) already exists and getContent().getSize() > 0.

Common situations: 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.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/122faed5d98cc257. Report an issue: GitHub.

Appendix: source

Thrown at plugins/pentaho-reporting/impl/src/main/java/org/pentaho/di/trans/steps/pentahoreporting/urlrepository/FileObjectContentLocation.java:160

   *
   * @param name the name of the new entity.
   * @return the newly created entity, never null.
   * @throws ContentCreationException if the item could not be created.
   */
  public ContentItem createItem( final String name ) throws ContentCreationException {
    String fileName = new File( name ).getName();
    if ( RepositoryUtilities.isInvalidPathName( fileName ) ) {
      throw new IllegalArgumentException( "The name given is not valid." );
    }
    try {
      final FileObject file = getBackend();
      final FileObject child = file.resolveFile( fileName );
      if ( child.exists() ) {
        if ( child.getContent().getSize() == 0 ) {
          // probably one of the temp files created by the pentaho-system
          return new FileObjectContentItem( this, child );
        }
        throw new ContentCreationException( "File already exists: " + child );
      }
      try {
        child.createFile();
        return new FileObjectContentItem( this, child );
      } catch ( IOException e ) {
        throw new ContentCreationException( "IOError while create", e );
      }
    } catch ( FileSystemException e ) {
      throw new RuntimeException( e );
    }
  }

  /**
   * Creates a new content location in the current location. This method must never return null. This method will fail
   * if an entity with the same name exists in this location.
   *
   * @param name the name of the new entity.
   * @return the newly created entity, never null.

View on GitHub (pinned to f3058517a1)