{"record":{"id":"0bd15a1caf048363","repo":"pentaho/pentaho-kettle","slug":"the-function-call-str2date-requires-1-2-3-or-4-arguments","errorCode":null,"errorMessage":"The function call str2date requires 1, 2, 3, or 4 arguments.","messagePattern":"The function call str2date requires 1, 2, 3, or 4 arguments\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1082,"sourceCode":"          // If the timezone is not recognized, java will automatically\n          // take GMT.\n          TimeZone tz = TimeZone.getTimeZone( sArg4 );\n\n          if ( sArg3.length() == 2 ) {\n            Locale dfLocale = EnvUtil.createLocale( sArg3 );\n            dfFormatter = new SimpleDateFormat( sArg2, dfLocale );\n            dfFormatter.setTimeZone( tz );\n            oRC = dfFormatter.parseObject( sArg1 );\n          } else {\n            throw new RuntimeException( \"Locale \" + sArg3 + \" is not 2 characters long.\" );\n          }\n        } catch ( Exception e ) {\n          throw new RuntimeException( \"Could not apply the local format for locale \"\n            + sArg3 + \" with the given format \" + sArg2 + \" on the string for \" + sArg1 + \" : \" + e.getMessage() );\n        }\n        break;\n      default:\n        throw new RuntimeException( \"The function call str2date requires 1, 2, 3, or 4 arguments.\" );\n    }\n    return oRC;\n  }\n\n  public static Object date2str( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    Object oRC = new Object();\n    switch ( ArgList.length ) {\n      case 0:\n        throw new RuntimeException( \"Please provide a valid date to the function call date2str.\" );\n      case 1:\n        try {\n          if ( isNull( ArgList ) ) {\n            return null;\n          } else if ( isUndefined( ArgList ) ) {\n            return undefinedValue;\n          }\n          java.util.Date dArg1 = (java.util.Date) ArgList[0];","sourceCodeStart":1064,"sourceCodeEnd":1100,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1064-L1100","documentation":"str2date only supports 1, 2, 3, or 4 arguments (date string, optional format, optional locale, optional timezone). Calling it with 0 or 5+ arguments falls into the switch default and throws this RuntimeException.","triggerScenarios":"Invoking str2date() with no arguments, or with 5+ arguments (e.g. accidentally passing extra parameters), from a JavaScript script step.","commonSituations":"Typos or refactored scripts leaving stray arguments; misunderstanding the signature and passing extra options; generated/templated script code emitting wrong argument counts.","solutions":["Call str2date with 1-4 arguments: the date string at minimum.","Remove extra arguments; format/locale/timezone are positional.","If you need more options, pre-process the string in script instead of adding arguments.","Check the script step's generated code (e.g. compatibility flags) that may alter argument lists."],"exampleFix":"// before\nvar d = str2date(s, 'yyyy-MM-dd', 'en', 'UTC', 'extra');\n// after\nvar d = str2date(s, 'yyyy-MM-dd', 'en', 'UTC');","handlingStrategy":"validation","validationCode":"if (arguments.length < 1 || arguments.length > 4) throw new Error('str2date requires 1-4 arguments, got ' + arguments.length);","typeGuard":null,"tryCatchPattern":"try { var d = str2date.apply(null, args.slice(0, 4)); } catch (e) { if (String(e.message).indexOf('requires 1, 2, 3, or 4 arguments') >= 0) { throw new Error('bad str2date call, args=' + args.length); } throw e; }","preventionTips":["Call str2date with at most 4 positional arguments (string, format, locale, timezone)","Never pass extra/optional config objects as additional arguments","Review generated script code for duplicated arguments","Always supply at least the date string"],"tags":["javascript","argument-count","scripting","api-misuse"],"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"}