{"record":{"id":"72f3ea4ce8df92c4","repo":"pentaho/pentaho-kettle","slug":"file-already-exists-fileobjectcontentlocation","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":189,"sourceCode":"  }\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.\n   * @throws ContentCreationException if the item could not be created.\n   */\n  public ContentLocation createLocation( final String name ) throws ContentCreationException {\n    if ( RepositoryUtilities.isInvalidPathName( name ) ) {\n      throw new IllegalArgumentException( \"The name given is not valid.\" );\n    }\n    try {\n      final FileObject file = getBackend();\n      final FileObject child = file.resolveFile( name );\n      if ( child.exists() ) {\n        throw new ContentCreationException( \"File already exists.\" );\n      }\n      child.createFile();\n      try {\n        return new FileObjectContentLocation( this, child );\n      } catch ( ContentIOException e ) {\n        throw new ContentCreationException( \"Failed to create the content-location\", e );\n      }\n    } catch ( FileSystemException e ) {\n      throw new RuntimeException( e );\n    }\n  }\n\n  /**\n   * Checks, whether an content entity with the given name exists in this content location. This method will report\n   * invalid filenames as non-existent.\n   *\n   * @param name the name of the new entity.\n   * @return true, if an entity exists with this name, false otherwise.","sourceCodeStart":171,"sourceCodeEnd":207,"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#L171-L207","documentation":"FileObjectContentLocation.createLocation(name) creates a sub-location; if the resolved child file object already exists it throws ContentCreationException 'File already exists.' instead of overwriting or returning the existing location.","triggerScenarios":"Calling createLocation(name) where file.resolveFile(name).exists() is true.","commonSituations":"Re-running a reporting job that creates the same sub-directory each run; concurrent jobs both attempting to create the same location; leftover artifacts from a previous failed run.","solutions":["Check existence first (getLocation(name) or exists) and reuse the existing location instead of creating.","Delete the existing location if a fresh directory is required.","Generate unique location names per run (timestamp/run-id).","Synchronize creation across concurrent workers."],"exampleFix":"// before\nContentLocation sub = location.createLocation(\"exports\");\n// after\nContentLocation sub = location.getLocation(\"exports\");\nif (sub == null) {\n  sub = location.createLocation(\"exports\");\n}","handlingStrategy":"validation","validationCode":"ContentLocation existing = location.getLocation(name); // null when absent\nboolean exists = existing != null;","typeGuard":null,"tryCatchPattern":"try {\n  sub = location.createLocation(name);\n} catch (ContentCreationException e) {\n  if (e.getMessage().equals(\"File already exists.\")) sub = location.getLocation(name);\n}","preventionTips":["Prefer getLocation() and create only when null.","Use run-specific directory names.","Clean leftovers from failed runs at job start."],"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"}