{"record":{"id":"253290609d3605db","repo":"pentaho/pentaho-kettle","slug":"the-function-call-rpad-requires-3-arguments","errorCode":null,"errorMessage":"The function call rpad requires 3 arguments.","messagePattern":"The function call rpad requires 3 arguments\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":822,"sourceCode":"    Object FunctionContext ) {\n    try {\n      if ( ArgList.length == 3 ) {\n        if ( isNull( ArgList, new int[] { 0, 1, 2 } ) ) {\n          return null;\n        } else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {\n          return (String) undefinedValue;\n        }\n        String valueToPad = (String) ArgList[0];\n        String filler = (String) ArgList[1];\n        int size = (Integer) ArgList[2];\n\n        while ( valueToPad.length() < size ) {\n          valueToPad = valueToPad + filler;\n        }\n        return valueToPad;\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( \"The function call rpad requires 3 arguments.\" );\n    }\n    return null;\n  }\n\n  public static Object year( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    try {\n      if ( ArgList.length == 1 ) {\n        if ( isNull( ArgList[0] ) ) {\n          return new Double( Double.NaN );\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return undefinedValue;\n        }\n        java.util.Date dArg1 = (java.util.Date) ArgList[0];\n        Calendar cal = Calendar.getInstance();\n        cal.setTime( dArg1 );\n        return new Double( cal.get( Calendar.YEAR ) );\n      } else {","sourceCodeStart":804,"sourceCodeEnd":840,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L804-L840","documentation":"rpad() right-pads a string to a target size with a filler string. Like lpad, it requires exactly three arguments; any missing argument or inner exception is converted to this RuntimeException and the function returns null.","triggerScenarios":"Calling rpad(value) or rpad(value, size) in a Script step, or a three-argument call whose processing throws (bad size type, null value), which lands in the same catch.","commonSituations":"Porting two-argument RPAD usage from other languages; building the argument list dynamically and dropping the filler argument.","solutions":["Call rpad with exactly three arguments: rpad(value, size, filler).","Ensure size is numeric and filler is a string.","Guard against null values before calling rpad.","Replace dynamic argument construction with a fixed three-argument call."],"exampleFix":"// before\nvar padded = rpad(name, 10);\n// after\nvar padded = rpad(name, 10, \" \");","handlingStrategy":"validation","validationCode":"if (value != null && typeof size === \"number\" && size > 0) { var padded = rpad(value, size, filler); }","typeGuard":"function canRpad(v, size, filler) { return v != null && typeof size === \"number\" && size > 0 && filler != null && String(filler).length > 0; }","tryCatchPattern":"try {\n  var padded = rpad(value, size, filler);\n  if (padded === null) { /* argument-count failure path */ }\n} catch (e) {\n  Logger.LogBasic(\"rpad failed: \" + e.message);\n  padded = value;\n}","preventionTips":["Pass exactly three arguments to rpad().","Validate size numerically before the call.","Use a non-empty string filler.","Check for null return values, which signal the failure path."],"tags":["javascript","script-step","argument-count","pentaho-kettle"],"backgroundTag":"missing-required-argument","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"}