{"record":{"id":"37027f10ed8f1c59","repo":"pentaho/pentaho-kettle","slug":"the-function-call-str2regexp-requires-2-arguments","errorCode":null,"errorMessage":"The function call str2RegExp requires 2 arguments.","messagePattern":"The function call str2RegExp requires 2 arguments\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":946,"sourceCode":"        if ( isNull( ArgList, new int[] { 0, 1 } ) ) {\n          return null;\n        } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {\n          return undefinedValue;\n        }\n        String strToMatch = (String) ArgList[0];\n        Pattern p = Pattern.compile( (String) ArgList[1] );\n        Matcher m = p.matcher( strToMatch );\n        if ( m.matches() && m.groupCount() > 0 ) {\n          strArr = new String[m.groupCount()];\n          for ( int i = 1; i <= m.groupCount(); i++ ) {\n            strArr[i - 1] = m.group( i );\n          }\n        }\n      } catch ( Exception e ) {\n        throw new RuntimeException( e.toString() );\n      }\n    } else {\n      throw new RuntimeException( \"The function call str2RegExp requires 2 arguments.\" );\n    }\n    return strArr;\n  }\n\n  public static void touch( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    try {\n      if ( ArgList.length == 1 && !isNull( ArgList[0] ) && !isUndefined( ArgList[0] ) ) {\n        File file = new File( (String) ArgList[0] );\n        boolean success = file.createNewFile();\n        if ( !success ) {\n          file.setLastModified( System.currentTimeMillis() );\n        }\n      } else {\n        throw new RuntimeException( \"The function call touch requires 1 valid argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( e.toString() );","sourceCodeStart":928,"sourceCodeEnd":964,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L928-L964","documentation":"str2RegExp() requires exactly two arguments (the string and the regular expression). When ArgList.length != 2 the function throws this RuntimeException instead of attempting a match. It is an arity guard thrown before any regex work happens.","triggerScenarios":"Calling str2RegExp with 0, 1, or 3+ arguments in a Modified Java Script Value step, e.g. str2RegExp(myField) forgetting the pattern argument.","commonSituations":"Copy-pasted script snippets where an argument was dropped; dynamic argument lists built in JavaScript whose length varies; refactorings that removed the pattern parameter.","solutions":["Call str2RegExp with exactly two arguments: str2RegExp(inputString, regexPattern).","If the regex may be empty conditionally, guard the call in script code before invoking.","Check the script step log for which call site passes the wrong number of arguments."],"exampleFix":"// before\nvar groups = str2RegExp(value);\n// after\nvar groups = str2RegExp(value, \"(\\w+)-(\\d+)\");","handlingStrategy":"validation","validationCode":"if (arguments.length !== 2) throw new RuntimeException('str2RegExp requires exactly 2 arguments');","typeGuard":null,"tryCatchPattern":"try { var g = str2RegExp(s, rx); } catch (e) { if (String(e.message).indexOf('requires 2 arguments') >= 0) { logError('call-site arity bug'); } }","preventionTips":["Always call str2RegExp with both string and pattern","Avoid building argument lists dynamically","Review scripts after refactoring field names"],"tags":["scripting","arity","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"}