{"record":{"id":"a10775fc81b0b112","repo":"pentaho/pentaho-kettle","slug":"java-lang-nullpointerexception-wrapped-row-too-short-for","errorCode":null,"errorMessage":"java.lang.NullPointerException (wrapped; row too short for index)","messagePattern":"java\\.lang\\.NullPointerException \\(wrapped; row too short for index\\)","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/common/CsvInputAwareHelper.java","lineNumber":200,"sourceCode":"    } catch ( final Exception e ) {\n      exc = e;\n    }\n\n    // if 'failOnParseError' is true, and we caught an exception, we either re-throw the exception, or wrap its as a\n    // KettleException, if it isn't one already\n    if ( failOnParseError ) {\n      if ( exc instanceof KettleException ) {\n        throw (KettleException) exc;\n      } else if ( exc != null ) {\n        throw new KettleException( exc );\n      }\n    }\n\n    // if 'failOnParseError' is false, or there is no exception otherwise, we get the string value straight from the row\n    // object\n    if ( string == null ) {\n      if ( ( row.length <= index ) && failOnParseError ) {\n        throw new KettleException( new NullPointerException() );\n      }\n      string = row.length <= index || row[ index ] == null ? null : row[ index ].toString();\n    }\n\n    return string;\n  }\n\n  /**\n   * Creates a buffered input stream reader for the given CSV input metadata and input stream.\n   *\n   * @param meta        the CSV input metadata\n   * @param inputStream the input stream to read from\n   * @return a BufferedInputStreamReader for reading the CSV file\n   */\n  default BufferedInputStreamReader getBufferedReader( final TransMeta transMeta, final CsvInputAwareMeta meta,\n                                                       final InputStream inputStream ) {\n    return new BufferedInputStreamReader( getReader( transMeta, meta, inputStream ) );\n  }","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/common/CsvInputAwareHelper.java#L182-L218","documentation":"In CsvInputAwareHelper.getStringFromRow, when failOnParseError is true and the requested index exceeds the row's length, a raw NullPointerException is thrown wrapped in a KettleException. The empty NPE gives no message, but the semantic is 'row too short for the requested field index'.","triggerScenarios":"row.length <= index and failOnParseError is true — the physical row has fewer columns than the defined field count (e.g. trailing empty line or truncated record).","commonSituations":"CSV files with blank trailing lines, ragged rows with missing trailing delimiters, wrong 'N of header lines' settings, or files where the last line lacks a newline and is mis-split.","solutions":["Remove/pre-filter blank or truncated lines from the input file","Check the step's header-line and field-count settings against the actual file","Enable error handling for the step so short rows go to an error stream instead of failing","Read the KettleException's cause (NullPointerException) as the signal that index exceeded row length"],"exampleFix":"// before\nfile.csv last line: 'a,b'\n// step defines 3 fields -> row too short\n// after\nensure every data line has all fields:\n'a,b,'\nor filter empty lines with a 'Filter rows' step on field1 <> ''","handlingStrategy":"validation","validationCode":"// check each line's column count before processing\nString[] cols = line.split(\",\", -1);\nif (cols.length < expectedFieldCount) skipBlankLine(line);","typeGuard":"boolean rowHasField(Object[] row, int index) {\n  return row != null && row.length > index;\n}","tryCatchPattern":"try { string = helper.getStringFromRow(row, index, false); }\ncatch (KettleException e) { if (e.getCause() instanceof NullPointerException) logError(\"Row too short: \" + row.length); throw e; }","preventionTips":["Strip trailing blank lines from CSV files","Ensure every row has all delimiters (trailing commas for empty fields)","Set correct header-line count in the step"],"tags":["pdi","csv","null-pointer","index-out-of-bounds"],"backgroundTag":"index-out-of-bounds","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"}