{"record":{"id":"81710027efc9f1a3","repo":"pentaho/pentaho-kettle","slug":"please-provide-a-valid-string-to-the-function-call-str2date","errorCode":null,"errorMessage":"Please provide a valid string to the function call str2date.","messagePattern":"Please provide a valid string to the function call str2date\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":994,"sourceCode":"        return Boolean.valueOf( file.isFile() );\n      } else {\n        throw new RuntimeException( \"The function call fileExists requires 1 valid argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( e.toString() );\n    }\n  }\n\n  public static Object str2date( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    Object oRC = new Object();\n    String sArg1 = \"\";\n    String sArg2 = \"\";\n    String sArg3 = \"\";\n    String sArg4 = \"\";\n    switch ( ArgList.length ) {\n      case 0:\n        throw new RuntimeException( \"Please provide a valid string to the function call str2date.\" );\n      case 1:\n        try {\n          if ( isNull( ArgList[0] ) ) {\n            return null;\n          } else if ( isUndefined( ArgList[0] ) ) {\n            return undefinedValue;\n          }\n          sArg1 = (String) ArgList[0];\n          Format dfFormatter = new SimpleDateFormat();\n          oRC = dfFormatter.parseObject( sArg1 );\n          // if(Double.isNaN(sArg1)) throw new RuntimeException(\"The first Argument must be a Number.\");\n          // DecimalFormat formatter = new DecimalFormat();\n          // sRC= formatter.format(sArg1);\n        } catch ( Exception e ) {\n          throw new RuntimeException( \"Could not apply local format for \" + sArg1 + \" : \" + e.getMessage() );\n        }\n        break;\n      case 2:","sourceCodeStart":976,"sourceCodeEnd":1012,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L976-L1012","documentation":"str2date() converts a string to a Date using an optional format. The switch on ArgList.length throws this RuntimeException in the case 0 branch — the function refuses to run with no arguments. At minimum the date string must be supplied.","triggerScenarios":"Calling str2date() with zero arguments in a Modified Java Script Value step, usually because the source field was deleted or renamed.","commonSituations":"Renaming a transformation field without updating the script; copy-pasting a script where the argument was lost; building the argument dynamically and producing undefined.","solutions":["Pass at least one argument: str2date('2026-09-13') or str2date(dateStringField).","If the field may be empty, return null early in script instead of calling str2date.","Check the script step's field mappings after transformation changes."],"exampleFix":"// before\nvar d = str2date();\n// after\nvar d = str2date(dateString, 'yyyy-MM-dd');","handlingStrategy":"validation","validationCode":"if (dateString == null || dateString.length === 0) { var d = null; } else { var d = str2date(dateString, 'yyyy-MM-dd'); }","typeGuard":null,"tryCatchPattern":"try { var d = str2date(s, fmt); } catch (e) { logError('str2date failed: ' + e.message); d = null; }","preventionTips":["Always supply at least the date string argument","Update script steps when renaming transformation fields","Return null for empty inputs instead of calling str2date"],"tags":["scripting","date","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"}