{"record":{"id":"9399f429b9de92e5","repo":"pentaho/pentaho-kettle","slug":"textfileinputdialog-exception-errorgettingfirstlines-9399f4","errorCode":null,"errorMessage":"TextFileInputDialog.Exception.ErrorGettingFirstLines","messagePattern":"TextFileInputDialog\\.Exception\\.ErrorGettingFirstLines","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"ui/src/main/java/org/pentaho/di/ui/trans/steps/textfileinput/TextFileInputDialog.java","lineNumber":2922,"sourceCode":"          // Skip the header lines first if more then one, it helps us position\n          if ( meta.hasHeader() && meta.getNrHeaderLines() > 0 ) {\n            int skipped = 0;\n            String line = TextFileInput.getLine( log, reader, encodingType, fileFormatType, lineStringBuilder );\n            while ( line != null && skipped < meta.getNrHeaderLines() - 1 ) {\n              skipped++;\n              line = TextFileInput.getLine( log, reader, encodingType, fileFormatType, lineStringBuilder );\n            }\n          }\n        }\n\n        String line = TextFileInput.getLine( log, reader, encodingType, fileFormatType, lineStringBuilder );\n        while ( line != null && ( linenr < maxnr || nrlines == 0 ) ) {\n          retval.add( line );\n          linenr++;\n          line = TextFileInput.getLine( log, reader, encodingType, fileFormatType, lineStringBuilder );\n        }\n      } catch ( Exception e ) {\n        throw new KettleException( BaseMessages.getString( PKG, \"TextFileInputDialog.Exception.ErrorGettingFirstLines\",\n            \"\" + nrlines, file.getName().getURI() ), e );\n      } finally {\n        try {\n          if ( f != null ) {\n            f.close();\n          }\n        } catch ( Exception e ) {\n          // Ignore errors\n        }\n      }\n    }\n\n    return retval;\n  }\n\n  private void getFixed() {\n    TextFileInputMeta info = new TextFileInputMeta();\n    getInfo( info );","sourceCodeStart":2904,"sourceCodeEnd":2940,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/ui/src/main/java/org/pentaho/di/ui/trans/steps/textfileinput/TextFileInputDialog.java#L2904-L2940","documentation":"TextFileInputDialog's constructor (first-lines fetching, getFirstLines path) reads up to maxnr initial lines using TextFileLine/TextFile.getLine. Any exception while reading those lines is wrapped in a KettleException keyed to TextFileInputDialog.Exception.ErrorGettingFirstLines, including the number of lines read so far and the file URI, with the original exception as cause.","triggerScenarios":"Opening the Text File Input dialog / sampling the file when the underlying VFS file cannot be read — missing file, IO error on the input stream, unsupported/incorrect encoding, or a broken compressed (zip/gzip) stream while pulling the first n lines.","commonSituations":"File path points to a non-existent or moved file; permission denied on network share; wrong encoding declared; corrupt zip/gzip archive; VFS URL (file.getName().getURI()) invalid or unreachable.","solutions":["Verify the file exists and is readable at the configured location/URI","Check the declared encoding matches the actual file encoding","If the file is compressed, validate the archive is not corrupt (unzip -t / gunzip -t)","Preview with a smaller number of sample lines and check file permissions/network access"],"exampleFix":"// before: reading a missing file\nString filename = \"/data/in/sales.csv\"; // file moved -> IO error while sampling\n// after: ensure path exists before opening dialog\nif ( new File( \"/data/in/sales.csv\" ).exists() ) { openDialog( \"/data/in/sales.csv\" ); }","handlingStrategy":"try-catch","validationCode":"// Java: verify the VFS file is resolvable and readable before sampling\norg.apache.commons.vfs2.FileObject fo = KettleVFS.getFileObject( filename );\nif ( !fo.exists() || !fo.isReadable() ) throw new IllegalStateException( \"Cannot read: \" + fo.getURI() );","typeGuard":"boolean fileReadable = filename != null && KettleVFS.fileExists( filename );","tryCatchPattern":"try { sampleFirstLines( file, maxnr ); } catch ( KettleException e ) { log.error( \"Failed reading first lines of \" + file.getName().getURI() + \": \" + e.getCause(), e ); }","preventionTips":["Verify file paths and network shares before opening the dialog","Match declared encoding to the actual file encoding","Validate compressed archives before using them as input"],"tags":["file-read","text-file-input","encoding","ui"],"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"}