{"record":{"id":"0e2829474454a76f","repo":"pentaho/pentaho-kettle","slug":"error-opening-new-file-logged-kettleexception-e","errorCode":null,"errorMessage":"Error opening new file (logged), KettleException( e )","messagePattern":"Error opening new file \\(logged\\), KettleException\\( e \\)","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"plugins/excel/core/src/main/java/org/pentaho/di/trans/steps/excelwriter/ExcelWriterStep.java","lineNumber":785,"sourceCode":"        data.innerSheet = Optional.of( data.sheet );\n        data.wb = new SXSSFWorkbook( (XSSFWorkbook) data.wb, STREAMING_WINDOW_SIZE );\n        data.sheet = data.wb.getSheet( data.realSheetname );\n      }\n\n      if ( log.isDebug() ) {\n        logDebug( BaseMessages.getString( PKG, \"ExcelWriterStep.Log.FileOpened\", buildFilename ) );\n      }\n      // this is the number of the new output file\n      data.splitnr++;\n    }  catch ( IOException | POIXMLException e ) {\n        throw new KettleException( BaseMessages.getString( PKG, \"ExcelInput.Log.UnsafeFileException\" ) +\n                e\n        );\n    }\n    catch ( Exception e ) {\n      logError( \"Error opening new file\", e );\n      setErrors( 1 );\n      throw new KettleException( e );\n    }\n  }\n\n  /** Sets data.startingRow, data.startingCol, data.posX, data.posY */\n  private void setSheetPosition( boolean appendingToSheet ) {\n    // starting cell support\n    if ( !Utils.isEmpty( data.realStartingCell ) ) {\n      CellReference cellRef = new CellReference( data.realStartingCell );\n      data.startingRow = cellRef.getRow();\n      data.startingCol = cellRef.getCol();\n    } else {\n      data.startingRow = 0;\n      data.startingCol = 0;\n    }\n\n    data.posX = data.startingCol;\n    data.posY = data.startingRow;\n","sourceCodeStart":767,"sourceCodeEnd":803,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/excel/core/src/main/java/org/pentaho/di/trans/steps/excelwriter/ExcelWriterStep.java#L767-L803","documentation":"The generic catch block of prepareNextOutputFile(): any exception while opening the new output Excel workbook (not IOException/POIXMLException, which get their own handler) is logged as 'Error opening new file', increments the step error count, and is rethrown as KettleException.","triggerScenarios":"Non-IO failures during file open: OutOfMemoryError-like conditions via RuntimeException, InvalidFormatException variants not covered by POIXMLException, or runtime errors in workbook setup (style creation, sheet position setup).","commonSituations":"Heap exhaustion opening large XLSX workbooks; corrupted pre-existing append target; unexpected POI runtime exception during XSSFWorkbook construction.","solutions":["Read the logged stack trace for the root cause","Increase the JVM heap (-Xmx) when opening large XLSX files","If appending to an existing file, verify it opens correctly in Excel and matches the extension","Upgrade POI/Kettle version if the trace indicates a POI bug"],"exampleFix":"// before: opening a huge xlsx in append mode with small heap\n// after: increase heap in kettle script\n# spoon.bat / kitchen.sh\n-Xmx4096m","handlingStrategy":"try-catch","validationCode":"File target = new File(filename);\nif (target.isDirectory()) throw new IllegalStateException(\"Output path is a directory\");\nif (!target.getParentFile().canWrite()) throw new IllegalStateException(\"No write access: \" + target.getParent());\nif (target.length() > 100_000_000L && append) throw new IllegalStateException(\"Append target too large for heap\");","typeGuard":null,"tryCatchPattern":"try { writer.prepareNextOutputFile(); }\ncatch (KettleException e) {\n  logError(\"Failed to open output: \" + e.getCause(), e);\n  setErrors(1);\n  throw e; // fail the transformation; partial file should be inspected\n}","preventionTips":["Increase JVM heap for large xlsx output","Validate existing append targets open correctly in Excel","Keep POI version current","Check output file is not locked by Excel"],"tags":["excel","poi","workbook-open","kettle"],"backgroundTag":"file-open-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"}