{"record":{"id":"51c213d04112b8bf","repo":"pentaho/pentaho-kettle","slug":"please-provide-a-valid-char-to-the-fillstring","errorCode":null,"errorMessage":"Please provide a valid Char to the fillString","messagePattern":"Please provide a valid Char to the fillString","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":697,"sourceCode":"      }\n    } else {\n      throw new RuntimeException( \"The function call dateAdd requires 3 arguments.\" );\n    }\n  }\n\n  public static String fillString( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    if ( ArgList.length == 2 ) {\n      try {\n        if ( isNull( ArgList, new int[] { 0, 1 } ) ) {\n          return null;\n        } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {\n          return (String) undefinedValue;\n        }\n        String fillChar = (String) ArgList[0];\n        int count = (Integer) ArgList[1];\n        if ( fillChar.length() != 1 ) {\n          throw new RuntimeException( \"Please provide a valid Char to the fillString\" );\n        } else {\n          char[] chars = new char[count];\n          while ( count > 0 ) {\n            chars[--count] = fillChar.charAt( 0 );\n          }\n          return new String( chars );\n        }\n      } catch ( Exception e ) {\n        throw new RuntimeException( e.toString() );\n      }\n    } else {\n      throw new RuntimeException( \"The function call fillString requires 2 arguments.\" );\n    }\n  }\n\n  public static Object isCodepage( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    boolean bRC = false;","sourceCodeStart":679,"sourceCodeEnd":715,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L679-L715","documentation":"fillString repeats a single character count times to produce a padded string. The first argument must be a string of exactly length 1; if fillChar.length() != 1 the function throws this RuntimeException. It is a value validation on the character argument, distinct from the argument-count check.","triggerScenarios":"Calling fillString('ab', 5) or fillString('', 5) — any first argument whose string length is not exactly 1 while the argument count itself is correct (2 arguments).","commonSituations":"Passing multi-character pad strings like '--' or '  ' expecting them to be repeated; passing an empty string because the field was empty in the stream.","solutions":["Pass exactly one character: fillString('-', 10) or fillString(' ', 10).","If you need a multi-character pad, use JavaScript repetition instead: new Array(n+1).join(pad).","Trim or validate the field feeding the argument before the call."],"exampleFix":"// before\nvar pad = fillString('--', 20);\n// after\nvar pad = fillString('-', 20);","handlingStrategy":"validation","validationCode":"if (typeof fillChar !== 'string' || fillChar.length !== 1) {\n  throw new Error('fillString first argument must be a single character');\n}\nvar padded = fillString(fillChar, count);","typeGuard":"function isSingleChar(v) { return typeof v === 'string' && v.length === 1; }","tryCatchPattern":"try {\n  var padded = fillString(fillChar, count);\n} catch (e) {\n  if (String(e.message).indexOf('valid Char') !== -1) {\n    var padded = fillString(String(fillChar).charAt(0), count);\n  } else { throw e; }\n}","preventionTips":["Always pass a one-character string, never multi-character pads or empty strings.","For repeated multi-character pads use new Array(n+1).join(pad) in JavaScript instead.","Validate stream fields for emptiness before using them as the fill character."],"tags":["javascript","argument-validation","string","pentaho-kettle"],"backgroundTag":"invalid-argument-value","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"}