{"record":{"id":"1d96091d53e055c4","repo":"pentaho/pentaho-kettle","slug":"the-function-call-rpad-requires-3-arguments-1d9609","errorCode":null,"errorMessage":"The function call rpad requires 3 arguments.","messagePattern":"The function call rpad requires 3 arguments\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":852,"sourceCode":"    Function 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) Context.getUndefinedValue();\n        }\n        String valueToPad = Context.toString( ArgList[0] );\n        String filler = Context.toString( ArgList[1] );\n        int size = (int) Context.toNumber( ArgList[2] );\n\n        while ( valueToPad.length() < size ) {\n          valueToPad = valueToPad + filler;\n        }\n        return valueToPad;\n      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( \"The function call rpad requires 3 arguments.\" );\n    }\n    return null;\n  }\n\n  public static Object year( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function 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 Context.getUndefinedValue();\n        }\n        java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[0], java.util.Date.class );\n        Calendar cal = Calendar.getInstance();\n        cal.setTime( dArg1 );\n        return new Double( cal.get( Calendar.YEAR ) );\n      } else {","sourceCodeStart":834,"sourceCodeEnd":870,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L834-L870","documentation":"The rpad() function pads a string on the right to a given size with a filler string. Like lpad(), it expects exactly 3 arguments and wraps any exception (argument count, null value, conversion failure) into this 'requires 3 arguments' runtime error.","triggerScenarios":"Calling rpad() in a modified JavaScript step with fewer than 3 arguments (e.g. rpad(field, 8)), or with a null value / non-numeric size causing an exception inside the padding loop.","commonSituations":"Scripts modeled on SQL RPAD (filler optional there), fields that arrive null, or size given as a string instead of a number.","solutions":["Call rpad() with exactly 3 arguments: value, target size, filler string.","Null-check the value before calling.","Ensure size is numeric and filler is a non-empty string.","Wrap the call in a conditional that uses a default filler when omitted."],"exampleFix":"// before\nvar padded = rpad(myField, 8);\n// after\nvar padded = rpad(myField, 8, ' ');","handlingStrategy":"validation","validationCode":"if (myField == null) throw 'rpad: value is null';\nvar padded = rpad(String(myField), 8, ' ');","typeGuard":"function canRpad(v, size, filler) { return v != null && typeof size === 'number' && typeof filler === 'string' && filler.length > 0; }","tryCatchPattern":"try { var padded = rpad(String(myField), 8, ' '); } catch (e) { var padded = String(myField); }","preventionTips":["Always supply all 3 arguments: value, size, filler","Null-check field values before padding","Keep size numeric; filler must be a non-empty string","Differentiate lpad vs rpad carefully in copy-pasted code"],"tags":["javascript","rhino","string-functions"],"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"}