{"record":{"id":"c3ce122b04405f08","repo":"pentaho/pentaho-kettle","slug":"throw-new-kettleexception-e-getfilesrowscount","errorCode":null,"errorMessage":"throw new KettleException( e );","messagePattern":"throw new KettleException\\( e \\);","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/getfilesrowscount/GetFilesRowsCount.java","lineNumber":170,"sourceCode":"                prevCR = false;\n              }\n\n            } else {\n              if ( buf[i] == data.separator ) {\n                data.rownr++;\n                // Maybe we won't have data after\n                data.foundData = false;\n              }\n            }\n          }\n        }\n      }\n      if ( isDetailed() ) {\n        logDetailed( BaseMessages.getString( PKG, \"GetFilesRowsCount.Log.RowsInFile\", data.file.toString(), \"\"\n          + data.rownr ) );\n      }\n    } catch ( Exception e ) {\n      throw new KettleException( e );\n    } finally {\n      // Close inputstream - not used except for counting\n      if ( data.fr != null ) {\n        BaseStep.closeQuietly( data.fr );\n        data.fr = null;\n      }\n    }\n\n  }\n\n  private boolean openNextFile() {\n    if ( data.last_file ) {\n      return false; // Done!\n    }\n\n    try {\n      if ( !meta.isFileField() ) {\n        if ( data.filenr >= data.files.nrOfFiles() ) {","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/getfilesrowscount/GetFilesRowsCount.java#L152-L188","documentation":"GetFilesRowsCount.getRowNumber() wraps any exception raised while scanning the currently open file to count its rows into a bare KettleException. The file is closed in the finally block, so the error means row counting for data.file failed before reaching the reported rownr.","triggerScenarios":"Called from openNextFile when reading the file via data.fr throws: IO error, charset decoding failure, or the configured row-count field cannot be parsed from the line.","commonSituations":"Binary or wrongly-encoded files opened as text; permission changes mid-read; huge files hitting IO errors; count field format mismatch with the file's separator settings.","solutions":["Check file encoding/charset configuration matches the file.","Verify the separator and row-count field settings align with file content.","Ensure the file is readable by the user running the transformation.","Inspect the wrapped cause (e) for the exact IO/parse failure."],"exampleFix":"// before\nreader = new InputStreamReader(input); // platform default charset\n// after\nreader = new InputStreamReader(input, Charset.forName(meta.getEncoding() != null ? meta.getEncoding() : \"UTF-8\"));","handlingStrategy":"try-catch","validationCode":"if (meta.getEncoding() != null && !Charset.isSupported(meta.getEncoding())) throw new IllegalArgumentException(\"Unsupported encoding: \" + meta.getEncoding());","typeGuard":null,"tryCatchPattern":"try { count = getRowNumber(...); } catch (KettleException e) { log.error(\"Row counting failed for file: \" + data.file, e.getCause()); } finally { /* file is closed by the step */ }","preventionTips":["Set the correct charset for each file","Ensure the separator matches the file layout","Check file permissions for the runtime user","Test on a small sample file first"],"tags":["kettle","file-read","row-count","io"],"backgroundTag":"file-read-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"}