{"record":{"id":"4e6dcf0704894838","repo":"pentaho/pentaho-kettle","slug":"sharedojects-writetofile-errorwritingfile","errorCode":"SharedOjects.WriteToFile.ErrorWritingFile","errorMessage":"SharedOjects.WriteToFile.ErrorWritingFile","messagePattern":"SharedOjects\\.WriteToFile\\.ErrorWritingFile","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/shared/SharedObjects.java","lineNumber":319,"sourceCode":"      out = new PrintStream( outputStream );\n\n      out.print( XMLHandler.getXMLHeader( Const.XML_ENCODING ) );\n      out.println( \"<\" + XML_TAG + \">\" );\n\n      Collection<SharedObjectInterface> collection = objectsMap.values();\n      for ( SharedObjectInterface sharedObject : collection ) {\n        String xmlContent = sharedObject.getXML();\n        out.println( xmlContent );\n      }\n      out.println( \"</\" + XML_TAG + \">\" );\n    } catch ( Exception e ) {\n      // restore file if something wrong\n      boolean isRestored = false;\n      if ( backupFileName != null ) {\n        restoreFileFromBackup( backupFileName );\n        isRestored = true;\n      }\n      throw new KettleException(\n        BaseMessages.getString( PKG, \"SharedOjects.WriteToFile.ErrorWritingFile\", isRestored ), e );\n    } finally {\n      if ( out != null ) {\n        out.flush();\n      }\n      if ( out != null ) {\n        out.close();\n      }\n      if ( out != null ) {\n        outputStream.close();\n      }\n    }\n  }\n\n  private FileObject getFileObjectFromKettleVFS( String filename ) throws KettleFileException {\n    return KettleVFS.getInstance( DefaultBowl.getInstance() ).getFileObject( filename );\n  }\n","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/shared/SharedObjects.java#L301-L337","documentation":"SharedObjects.writeToFile() wraps any IOException thrown while writing the shared objects XML file into a KettleException with localized message 'SharedOjects.WriteToFile.ErrorWritingFile'. Before throwing, it attempts to restore the original file from the .backup copy so the user's shared objects file (kettle.properties-style shared objects, e.g. databases/steps saved as shared) is not lost. The boolean flag indicates whether the backup was restored.","triggerScenarios":"Calling saveToFile() on a SharedObjects instance when the underlying file cannot be written: disk full, read-only filesystem, missing write permission on the file/directory, or the output stream failing mid-write.","commonSituations":"Running Spoon/Carte/PDI jobs whose user lacks write access to ~/.kettle or the shared-objects directory; read-only container filesystems; full disks during long transformation runs; antivirus/backup tools locking the shared.xml file on Windows.","solutions":["Check free disk space and free some if the volume is full","Grant the running user write permission on the shared objects file and its directory (e.g. ~/.kettle)","Verify the filesystem is mounted read-write; remount or fix container volume settings","Restore manually from the .backup file next to the shared objects file if it is corrupted","Check the wrapped cause (KettleException.getCause()) for the exact IOException"],"exampleFix":"// before\nsharedObjects.saveToFile(); // throws KettleException on IO failure\n// after\ntry {\n  sharedObjects.saveToFile();\n} catch ( KettleException e ) {\n  boolean restored = e.getMessage().contains( \"restored\" ); // check log\n  logError( \"Could not write shared objects file; backup restored=\" + restored, e );\n}","handlingStrategy":"try-catch","validationCode":"java.io.File f = new java.io.File( sharedObjects.getFilename() );\nif ( !f.getParentFile().canWrite() || f.exists() && !f.canWrite() ) {\n  throw new IllegalStateException( \"Cannot write shared objects file: \" + f );\n}\nif ( f.getUsableSpace() < 1024 * 1024 ) {\n  throw new IllegalStateException( \"Low disk space\" );\n}","typeGuard":null,"tryCatchPattern":"try {\n  sharedObjects.saveToFile();\n} catch ( KettleException e ) {\n  Throwable root = e; while ( root.getCause() != null ) root = root.getCause();\n  logger.error( \"Shared objects write failed (backup may have been restored): {}\", root.getMessage(), e );\n}","preventionTips":["Ensure the process user owns/can write ~/.kettle and the shared objects file","Monitor free disk space on the volume holding the shared objects file","Keep the .backup file next to the shared objects file intact","In containers, mount the config directory read-write"],"tags":["io","file-write","pdi"],"backgroundTag":"file-write-failed","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"}