{"record":{"id":"78f65346c16d42b0","repo":"pentaho/pentaho-kettle","slug":"the-function-call-rtrim-is-not-valid","errorCode":null,"errorMessage":"The function call rtrim is not valid : ","messagePattern":"The function call rtrim is not valid : ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":773,"sourceCode":"    }\n  }\n\n  public static String rtrim( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object 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) undefinedValue;\n        }\n        String strValueToTrim = (String) ArgList[0];\n        return strValueToTrim.replaceAll( \"\\\\s+$\", \"\" );\n      } else {\n        throw new RuntimeException( \"The function call rtrim requires 1 argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( \"The function call rtrim is not valid : \" + e.getMessage() );\n    }\n  }\n\n  public static String lpad( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object 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) undefinedValue;\n        }\n        String valueToPad = (String) ArgList[0];\n        String filler = (String) ArgList[1];\n        int size = (Integer) ArgList[2];\n","sourceCodeStart":755,"sourceCodeEnd":791,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L755-L791","documentation":"rtrim() is one of the JavaScript helper functions Kettle injects into the Script step. It strips trailing whitespace with strValueToTrim.replaceAll(\"\\\\s+$\", \"\"). Any exception inside the function (bad argument count, non-String first argument, null input) is caught and rethrown as this generic RuntimeException, so the original cause is only visible in e.getMessage().","triggerScenarios":"Calling rtrim() in a Script step with zero arguments, more than one argument, or with an argument that is not a String and cannot be cast (ClassCastException) or otherwise fails during the regex replaceAll.","commonSituations":"Passing a numeric or Date field instead of a string field; passing null from an upstream step; accidentally passing two arguments expecting (value, chars) semantics like some SQL dialects.","solutions":["Pass exactly one argument and ensure it is a string (wrap with str() or concatenation with \"\" if needed).","Check e.getMessage() in the stack trace to see the underlying cause (argument count vs ClassCastException).","Handle null inputs before calling rtrim, e.g. if (v != null) v = rtrim(v).","If non-string trimming semantics are needed, implement it directly in the script instead of relying on rtrim."],"exampleFix":"// before\nvar trimmed = rtrim(myNumericField);\n// after\nvar trimmed = rtrim(str(myNumericField));","handlingStrategy":"type-guard","validationCode":"var trimmed = (value != null) ? rtrim(String(value)) : null;","typeGuard":"function isTrimSafe(v) { return v != null && (v instanceof java.lang.String || typeof v === \"string\"); }","tryCatchPattern":"try {\n  var trimmed = rtrim(value);\n} catch (e) {\n  // message is 'The function call rtrim is not valid : ' + cause\n  Logger.LogBasic(\"rtrim failed: \" + e.message);\n  trimmed = value;\n}","preventionTips":["Always pass exactly one string argument to rtrim().","Coerce non-string fields with str() before trimming.","Null-check upstream fields before calling.","Remember rtrim takes no character-set argument; do custom trimming for that."],"tags":["javascript","script-step","argument-count","type-mismatch","pentaho-kettle"],"backgroundTag":"invalid-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"}