{"record":{"id":"5a639b9a20bd5dec","repo":"pentaho/pentaho-kettle","slug":"the-function-call-str2num-requires-at-least-1-argument","errorCode":null,"errorMessage":"The function call str2num requires at least 1 argument.","messagePattern":"The function call str2num requires at least 1 argument\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1371,"sourceCode":"          }\n        } catch ( Exception e ) {\n          throw new RuntimeException( e.toString() );\n        }\n        break;\n      default:\n        throw new RuntimeException( \"The function call num2str requires 1, 2, or 3 arguments.\" );\n    }\n\n    return sRC;\n  }\n\n  // Converts the given String to a JScript Numeric\n  public static Object str2num( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    double dRC = 0.00;\n    switch ( ArgList.length ) {\n      case 0:\n        throw new RuntimeException( \"The function call str2num requires at least 1 argument.\" );\n      case 1:\n        try {\n          if ( isNull( ArgList[0] ) ) {\n            return new Double( Double.NaN );\n          } else if ( isUndefined( ArgList[0] ) ) {\n            return undefinedValue;\n          }\n          if ( ArgList[0].equals( null ) ) {\n            return null;\n          }\n          String sArg1 = (String) ArgList[0];\n          DecimalFormat formatter = new DecimalFormat();\n          dRC = ( formatter.parse( Const.ltrim( sArg1 ) ) ).doubleValue();\n        } catch ( Exception e ) {\n          throw new RuntimeException( \"Could not convert the given String : \" + e.getMessage() );\n        }\n        break;\n      case 2:","sourceCodeStart":1353,"sourceCodeEnd":1389,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1353-L1389","documentation":"str2num() converts a string to a number using DecimalFormat; the switch over ArgList.length throws this RuntimeException in the case 0 branch when the function is called with no arguments at all, since there is nothing to parse.","triggerScenarios":"Calling str2num() with zero arguments in a JavaScript script in the Pentaho Kettle scripting step.","commonSituations":"Variable holding the string is undefined, so the call effectively passes nothing; refactoring dropped the argument; copy-paste omitted the parameter.","solutions":["Pass at least one string argument to str2num.","Guard before calling: if (s != null && s.length > 0) str2num(s).","Provide a default: str2num(s || \"0\")."],"exampleFix":"// before\nvar n = str2num();\n// after\nvar n = (s == null) ? 0 : str2num(s);","handlingStrategy":"validation","validationCode":"if (s != null && typeof s === \"string\" && s.trim().length > 0) { var n = str2num(s); }","typeGuard":"function isNonEmptyString(v) { return typeof v === \"string\" && v.length > 0; }","tryCatchPattern":"try { return str2num(s); } catch (e) { return Number.NaN; }","preventionTips":["Check the string variable is defined before calling str2num","Provide defaults for possibly-undefined script variables","Only call str2num inside a non-empty-string check"],"tags":["argument-count","str2num","javascript-scripting"],"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"}