{"record":{"id":"ed1ffbea93b52f43","repo":"pentaho/pentaho-kettle","slug":"end-of-file-reached-while-reading-value","errorCode":null,"errorMessage":"End of file reached while reading value","messagePattern":"End of file reached while reading value","errorType":"exception","errorClass":"KettleEOFException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/compatibility/Value.java","lineNumber":1775,"sourceCode":"            if ( dis.readBoolean() ) {\n              setValue( new Date( dis.readLong() ) );\n            }\n            break;\n          case VALUE_TYPE_NUMBER:\n            setValue( dis.readDouble() );\n            break;\n          case VALUE_TYPE_INTEGER:\n            setValue( dis.readLong() );\n            break;\n          case VALUE_TYPE_BOOLEAN:\n            setValue( dis.readBoolean() );\n            break;\n          default:\n            break;\n        }\n      }\n    } catch ( EOFException e ) {\n      throw new KettleEOFException( \"End of file reached while reading value\", e );\n    } catch ( Exception e ) {\n      throw new KettleEOFException( \"Error reading value data from stream\", e );\n    }\n  }\n\n  /**\n   * Compare 2 values of the same or different type! The comparison of Strings is case insensitive\n   *\n   * @param v\n   *          the value to compare with.\n   * @return -1 if The value was smaller, 1 bigger and 0 if both values are equal.\n   */\n  public int compare( Value v ) {\n    return compare( v, true );\n  }\n\n  /**\n   * Compare 2 values of the same or different type!","sourceCodeStart":1757,"sourceCodeEnd":1793,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/compatibility/Value.java#L1757-L1793","documentation":"This KettleEOFException is thrown by the Value.readObj method (invoked via the Value(InputStream) constructor and other deserialization paths) when an EOFException occurs partway through reading the value's type-specific data. It means the stream ended before all fields of the current value were consumed, i.e. truncated input.","triggerScenarios":"Deserializing a sequence of Values when the stream is shorter than the expected value payload: truncated data file, closed socket mid-record, or a reader loop that keeps constructing Values after the stream is exhausted.","commonSituations":"Interrupted file transfer; producer crashed before flush/close; reading a Kettle binary file with a wrong expected record count; concurrent read/write on the same stream position.","solutions":["Verify the stream/file is complete (compare byte count with what the writer reported) and re-transfer if truncated.","Stop the read loop when the stream is exhausted instead of attempting further Value constructions.","Use higher-level Kettle APIs (KettleFileTransaction / RowMeta.getRow) that signal clean end-of-data.","Ensure the producer closes and flushes before the consumer reads to EOF.","Catch KettleEOFException to detect end-of-data vs. KettleFileException for genuine corruption."],"exampleFix":"// before\nwhile ( true ) { Value v = new Value( in ); rows.add( v ); } // throws at EOF\n// after\ntry {\n  while ( true ) { rows.add( new Value( in ) ); }\n} catch ( KettleEOFException e ) {\n  // normal end of data\n}","handlingStrategy":"try-catch","validationCode":"// verify expected payload size before deserializing a record sequence\nlong expected = recordCount * avgRecordBytes; // or use stored length prefixes\nif ( file.length() < expected ) throw new IOException( \"File truncated: \" + file.length() + \" < \" + expected );","typeGuard":"boolean hasData( InputStream in ) throws IOException {\n  in.mark( 1 );\n  int b = in.read();\n  in.reset();\n  return b != -1;\n}","tryCatchPattern":"try {\n  while ( hasData( in ) ) { rows.add( new Value( in ) ); }\n} catch ( KettleEOFException e ) {\n  log.warn( \"Stream ended mid-value; expected \" + recordCount + \" rows, got \" + rows.size() );\n}","preventionTips":["Compare producer-reported byte/record counts with what was consumed.","Check stream availability before constructing each Value.","Use higher-level Kettle row APIs with built-in EOF handling.","Ensure producers flush/close before consumers read.","Re-transfer truncated files automatically."],"tags":["io","deserialization","eof","streaming"],"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"}