{"record":{"id":"01ffe8a02ee1a13f","repo":"pentaho/pentaho-kettle","slug":"the-function-call-rtrim-requires-1-argument-01ffe8","errorCode":null,"errorMessage":"The function call rtrim requires 1 argument.","messagePattern":"The function call rtrim requires 1 argument\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":800,"sourceCode":"      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( \"The function call ltrim is not valid : \" + e.getMessage() );\n    }\n  }\n\n  public static String rtrim( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    try {\n      if ( ArgList.length == 1 ) {\n        if ( isNull( ArgList[0] ) ) {\n          return null;\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return (String) Context.getUndefinedValue();\n        }\n        String strValueToTrim = Context.toString( ArgList[0] );\n        return strValueToTrim.replaceAll( \"\\\\s+$\", \"\" );\n      } else {\n        throw Context.reportRuntimeError( \"The function call rtrim requires 1 argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( \"The function call rtrim is not valid : \" + e.getMessage() );\n    }\n  }\n\n  public static String lpad( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n\n    // (String valueToPad, String filler, int size) {\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] );","sourceCodeStart":782,"sourceCodeEnd":818,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L782-L818","documentation":"Argument-count guard in ScriptValuesAddedFunctions.rtrim, which strips trailing whitespace from a string. It fires when a JavaScript script calls rtrim with an argument count other than exactly 1; the guard raises a Rhino runtime error. Fix by calling rtrim with exactly one string argument.","triggerScenarios":"Calling rtrim() with no arguments, or rtrim(str, chars) with a SQL-style character-set second argument the implementation does not support.","commonSituations":"Porting Oracle/SQL Server RTRIM(expr, chars) calls; accidentally splitting arguments; piping a two-element array where one string was expected.","solutions":["Call with a single string argument: rtrim(myString)","For custom trailing characters, use myString.replace(/[chars]+$/, '') directly","Confirm the upstream field contains a single string value"],"exampleFix":"// before\nvar s = rtrim(value, '\\t');\n// after\nvar s = rtrim(value);","handlingStrategy":"type-guard","validationCode":"if (typeof s !== 'string') s = String(s == null ? '' : s);\nvar t = rtrim(s);","typeGuard":"function isStr(v) { return typeof v === 'string'; }","tryCatchPattern":"try { var t = rtrim(s); } catch (e) { if (String(e).indexOf('requires 1 argument') >= 0) { /* fix arity */ } else { throw e; } }","preventionTips":["Call rtrim with exactly one string argument","Use regex /[chars]+$/ for custom trailing characters","Do not pass SQL-style second arguments"],"tags":["javascript","kettle","string","argument-count"],"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"}