{"record":{"id":"089101061959f57d","repo":"pentaho/pentaho-kettle","slug":"unexpected-error-while-encoding-binary-fields","errorCode":null,"errorMessage":"Unexpected error while encoding binary fields","messagePattern":"Unexpected error while encoding binary fields","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/textfileoutput/TextFileOutput.java","lineNumber":904,"sourceCode":"          data.binaryNewline = environmentSubstitute( meta.getNewline() ).getBytes();\n        }\n      }\n\n      data.binaryNullValue = new byte[meta.getOutputFields().length][];\n      for ( int i = 0; i < meta.getOutputFields().length; i++ ) {\n        data.binaryNullValue[i] = null;\n        String nullString = meta.getOutputFields()[i].getNullString();\n        if ( !Utils.isEmpty( nullString ) ) {\n          if ( data.hasEncoding ) {\n            data.binaryNullValue[i] = nullString.getBytes( meta.getEncoding() );\n          } else {\n            data.binaryNullValue[i] = nullString.getBytes();\n          }\n        }\n      }\n      data.splitEvery = meta.getSplitEvery( variables );\n    } catch ( Exception e ) {\n      throw new KettleException( \"Unexpected error while encoding binary fields\", e );\n    }\n  }\n\n  protected void close() throws IOException {\n    if ( !meta.isServletOutput() ) {\n      data.getFileStreamsCollection().flushOpenFiles( true );\n    }\n  }\n\n  public void dispose( StepMetaInterface smi, StepDataInterface sdi ) {\n    meta = (TextFileOutputMeta) smi;\n    data = (TextFileOutputData) sdi;\n\n    try {\n      close();\n    } catch ( Exception e ) {\n      logError( \"Unexpected error closing file\", e );\n      setErrors( 1 );","sourceCodeStart":886,"sourceCodeEnd":922,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/textfileoutput/TextFileOutput.java#L886-L922","documentation":"In the TextFileOutput constructor the step precomputes binary separators, enclosures, newlines and null values using the configured encoding. Any unexpected exception during this binary-field setup is wrapped in KettleException 'Unexpected error while encoding binary fields'.","triggerScenarios":"Encoding a separator/enclosure/null string fails in init (e.g. unsupported charset, invalid regex-based escape handling, NPE on meta fields) during step initialization.","commonSituations":"Invalid step metadata (missing separator or encoding), charset unsupported, corrupted transformation metadata after upgrade.","solutions":["Reopen the step dialog and re-set separator, enclosure and encoding values","Verify the configured encoding is supported by the JVM","Reload/re-save the transformation to repair corrupted metadata"],"exampleFix":"// before\nmeta.setEncoding( \"x-custom-charset\" );\n// after\nmeta.setEncoding( \"UTF-8\" );","handlingStrategy":"try-catch","validationCode":"if ( meta.getEncoding() != null && !java.nio.charset.Charset.isSupported( meta.getEncoding() ) ) throw new IllegalArgumentException( \"Unsupported encoding in step metadata\" );","typeGuard":null,"tryCatchPattern":"try { init(); } catch ( KettleException e ) { logError( \"Step init failed while encoding binary fields: \" + e.getCause() ); throw e; }","preventionTips":["Re-save step metadata after upgrades","Use standard encodings/separators","Validate transformation XML when importing from other environments"],"tags":["kettle","pentaho","init","encoding"],"backgroundTag":"module-init-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"}