{"record":{"id":"ce4f2b86f30d2482","repo":"pentaho/pentaho-kettle","slug":"the-function-call-upper-is-not-valid-e-getmessage","errorCode":null,"errorMessage":"The function call upper is not valid : \" + e.getMessage()","messagePattern":"The function call upper is not valid : \" \\+ e\\.getMessage\\(\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1265,"sourceCode":"    } else {\n      throw new RuntimeException( \"The function call sendMail requires 5 arguments.\" );\n    }\n  }\n\n  public static String upper( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    String sRC = \"\";\n    if ( ArgList.length == 1 ) {\n      try {\n        if ( isNull( ArgList[0] ) ) {\n          return null;\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return (String) undefinedValue;\n        }\n        sRC = (String) ArgList[0];\n        sRC = sRC.toUpperCase();\n      } catch ( Exception e ) {\n        throw new RuntimeException( \"The function call upper is not valid : \" + e.getMessage() );\n      }\n    } else {\n      throw new RuntimeException( \"The function call upper requires 1 argument.\" );\n    }\n    return sRC;\n  }\n\n  public static String lower( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    String sRC = \"\";\n    if ( ArgList.length == 1 ) {\n      try {\n        if ( isNull( ArgList[0] ) ) {\n          return null;\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return (String) undefinedValue;\n        }\n        sRC = (String) ArgList[0];","sourceCodeStart":1247,"sourceCodeEnd":1283,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1247-L1283","documentation":"Thrown by the upper() helper of the PDI Script step when toUpperCase() fails on the supplied argument — typically because the argument is not a String (cast to String fails) or another exception occurs during conversion.","triggerScenarios":"Calling upper(x) with 1 argument where x is a non-string object that cannot be cast to java.lang.String (e.g. a Date or number object in certain engines) — the ClassCastException inside the try is wrapped with this message.","commonSituations":"Passing a numeric or Date field directly instead of converting to string first; passing null-ish script values in engines where the isNull/isUndefined checks did not cover the value.","solutions":["Convert the value to a string first: upper('' + myField) or upper(num2str(myField)).","Check the input field type in the transform preceding the Script step and add a 'Select values' step to type it as String.","Inspect e.getMessage() in the message to identify the concrete cause."],"exampleFix":"// before\nupper(orderDate)\n// after\nupper('' + orderDate)","handlingStrategy":"type-guard","validationCode":"function safeUpper(v) { return (v === null || v === undefined) ? null : upper(String(v)); }","typeGuard":"function isString(v) { return typeof v === 'string' || v instanceof java.lang.String; }","tryCatchPattern":"try { return upper(v); }\ncatch (e) { if (/upper is not valid/.test(e.message)) return String(v).toUpperCase(); throw e; }","preventionTips":["Ensure upstream fields are typed String via 'Select values'.","Coerce with String(v) or '' + v before calling string helpers.","Never pass Date/number objects directly to upper()."],"tags":["javascript","scripting-step","string","type-mismatch"],"backgroundTag":"type-mismatch","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"}