pentaho/pentaho-kettle · error · RuntimeException

The function call str2num requires at least 1 argument.

Error message

The function call str2num requires at least 1 argument.

What it means

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.

Solutions

  1. Pass at least one string argument to str2num.
  2. Guard before calling: if (s != null && s.length > 0) str2num(s).
  3. Provide a default: str2num(s || "0").

Example fix

// before
var n = str2num();
// after
var n = (s == null) ? 0 : str2num(s);
Defensive patterns

Strategy: validation

Validate before calling

if (s != null && typeof s === "string" && s.trim().length > 0) { var n = str2num(s); }

Type guard

function isNonEmptyString(v) { return typeof v === "string" && v.length > 0; }

Try / catch

try { return str2num(s); } catch (e) { return Number.NaN; }

Prevention

When it happens

Trigger: Calling str2num() with zero arguments in a JavaScript script in the Pentaho Kettle scripting step.

Common situations: Variable holding the string is undefined, so the call effectively passes nothing; refactoring dropped the argument; copy-paste omitted the parameter.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/5a639b9a20bd5dec. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java:1371

          }
        } catch ( Exception e ) {
          throw new RuntimeException( e.toString() );
        }
        break;
      default:
        throw new RuntimeException( "The function call num2str requires 1, 2, or 3 arguments." );
    }

    return sRC;
  }

  // Converts the given String to a JScript Numeric
  public static Object str2num( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
    Object FunctionContext ) {
    double dRC = 0.00;
    switch ( ArgList.length ) {
      case 0:
        throw new RuntimeException( "The function call str2num requires at least 1 argument." );
      case 1:
        try {
          if ( isNull( ArgList[0] ) ) {
            return new Double( Double.NaN );
          } else if ( isUndefined( ArgList[0] ) ) {
            return undefinedValue;
          }
          if ( ArgList[0].equals( null ) ) {
            return null;
          }
          String sArg1 = (String) ArgList[0];
          DecimalFormat formatter = new DecimalFormat();
          dRC = ( formatter.parse( Const.ltrim( sArg1 ) ) ).doubleValue();
        } catch ( Exception e ) {
          throw new RuntimeException( "Could not convert the given String : " + e.getMessage() );
        }
        break;
      case 2:

View on GitHub (pinned to f3058517a1)