{"record":{"id":"a0272716ab768851","repo":"pentaho/pentaho-kettle","slug":"csvinput-exception-createfieldmappingerror","errorCode":null,"errorMessage":"CsvInput.Exception.CreateFieldMappingError","messagePattern":"CsvInput\\.Exception\\.CreateFieldMappingError","errorType":"exception","errorClass":"KettleFileException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/csvinput/CsvInput.java","lineNumber":477,"sourceCode":"      InputStreamReader reader = null;\n      if ( Utils.isEmpty( realEncoding ) ) {\n        reader = new InputStreamReader( inputStream );\n      } else {\n        reader = new InputStreamReader( inputStream, realEncoding );\n      }\n      EncodingType encodingType = EncodingType.guessEncodingType( reader.getEncoding() );\n      String line =\n          TextFileInput.getLine( log, reader, encodingType, TextFileInputMeta.FILE_FORMAT_UNIX, new StringBuilder(\n              1000 ) );\n      String[] fieldNames =\n          CsvInput.guessStringsFromLine( log, line, delimiter, enclosure, csvInputMeta.getEscapeCharacter() );\n      if ( !Utils.isEmpty( csvInputMeta.getEnclosure() ) ) {\n        removeEnclosure( fieldNames, csvInputMeta.getEnclosure() );\n      }\n      trimFieldNames( fieldNames );\n      return fieldNames;\n    } catch ( IOException e ) {\n      throw new KettleFileException( BaseMessages.getString( PKG, \"CsvInput.Exception.CreateFieldMappingError\" ), e );\n    }\n  }\n\n  static String[] fieldNames( CsvInputMeta csvInputMeta ) {\n    TextFileInputField[] fields = csvInputMeta.getInputFields();\n    String[] fieldNames = new String[fields.length];\n    for ( int i = 0; i < fields.length; i++ ) {\n      // We need to sanitize field names because existing ktr files may contain field names with leading BOM\n      fieldNames[i] = EncodingType.removeBOMIfPresent( fields[i].getName() );\n    }\n    return fieldNames;\n  }\n\n  static void trimFieldNames( String[] strings ) {\n    if ( strings != null ) {\n      for ( int i = 0; i < strings.length; i++ ) {\n        strings[ i ] = strings[ i ].trim();\n      }","sourceCodeStart":459,"sourceCodeEnd":495,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/csvinput/CsvInput.java#L459-L495","documentation":"readFieldNamesFromFile opens the CSV file and parses the header line to build the field mapping. Any IOException during this process (file unreadable mid-read, decoding failure, stream error) is wrapped in a KettleFileException carrying the 'CreateFieldMappingError' message, indicating the step could not derive field names from the file's first line.","triggerScenarios":"IOException raised while reading the first line(s) of the CSV file in readFieldNamesFromFile — e.g. the file is deleted/locked after being opened, encoding issues causing a read failure, or the underlying channel errors out during header parse. Called via the static fieldNames() path / 'Get fields' in the dialog.","commonSituations":"Clicking 'Get fields from header row' in the step dialog against a locked, moved, or undecodable file; wrong charset configured so the byte stream cannot be decoded; file truncated or on a flaky network share.","solutions":["Re-check the file is accessible and not locked by another process.","Verify the encoding configured in the step matches the file's actual charset.","Re-select/refresh the file path in the dialog and retry 'Get fields'.","Open the file with a plain editor to confirm it is a valid, non-corrupt CSV."],"exampleFix":"// before: encoding mismatch\nEncoding = \"UTF-16\"\n// after\nEncoding = \"UTF-8\"","handlingStrategy":"try-catch","validationCode":"// verify the file's header is readable with the configured encoding before parsing\nbyte[] head = java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(filename));\nString header = new String(head, 0, Math.min(head.length, 4096), java.nio.charset.Charset.forName(encoding));\nif (header.isEmpty()) throw new IllegalStateException(\"Empty or undecodable header: \" + filename);","typeGuard":null,"tryCatchPattern":"try { ... } catch (KettleFileException e) {\n  logError(\"Could not read header from CSV: \" + e.getCause(), e);\n  setErrors(1);\n}","preventionTips":["Match the step's encoding setting to the file's actual charset","Confirm the file is not locked/open in another tool before 'Get fields'","Validate the file opens in a plain editor first","Check file permissions on network shares"],"tags":["kettle","pentaho","io-exception","header-parse"],"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"}