pentaho/pentaho-kettle · error
The function call indexOf requires 2 or 3 arguments
Error message
The function call indexOf requires 2 or 3 arguments
What it means
indexOf is a custom Rhino string helper that finds a substring and requires exactly 2 or 3 arguments (string, substring, optional fromIndex). Any other count throws the Rhino RuntimeError 'The function call indexOf requires 2 or 3 arguments'.
Solutions
- Call indexOf(str, subString) with the target string first.
- Add the optional third fromIndex argument only as a number.
- Remove any arguments beyond the third.
Example fix
// before var i = value.indexOf(sub); // wrong: only 1 arg to helper // after var i = indexOf(value, sub);
Defensive patterns
Strategy: type-guard
Validate before calling
// JS guard before calling if (str === null || str === undefined || sub === undefined) return -1; var i = indexOf(String(str), String(sub));
Type guard
function safeIndexOf(str, sub, fromIndex) {
if (str === null || str === undefined || sub === undefined) return -1;
return (fromIndex === undefined) ? indexOf(String(str), String(sub))
: indexOf(String(str), String(sub), Number(fromIndex));
} Try / catch
try { var i = indexOf(s, sub); }
catch (e) { if (String(e).indexOf('2 or 3 arguments') >= 0) { /* fix arity */ } throw e; } Prevention
- Remember this helper takes (string, substring) unlike native indexOf
- Don't pass more than the optional third argument
- Coerce inputs to strings
- Test the script in Spoon before saving the transformation
When it happens
Trigger: Calling indexOf with only one argument (JS-style str.indexOf(sub) confusion — this helper takes the string as the first argument), or with more than 3 arguments.
Common situations: Using native JavaScript indexOf syntax (value.indexOf(sub)) with this helper instead; passing extra flags as a 4th argument; forgetting the substring argument.
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
- The function call getDigitsOnly requires 1 argument.
- The function call LuhnCheck requires 1 argument.
- The function call copyFileis not valid.
- The function call getFileSize is not valid.
- The function call isEmpty is not valid
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/c62ec06d145e984d.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:195
public static int indexOf( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
int returnIndex = -1;
if ( ArgList.length == 2 || ArgList.length == 3 ) {
if ( !isNull( ArgList ) && !isUndefined( ArgList ) ) {
String string = Context.toString( ArgList[0] );
String subString = Context.toString( ArgList[1] );
int fromIndex = 0;
if ( ArgList.length == 3 ) {
fromIndex = (int) Math.round( Context.toNumber( ArgList[2] ) );
}
returnIndex = string.indexOf( subString, fromIndex );
}
} else {
throw Context.reportRuntimeError( "The function call indexOf requires 2 or 3 arguments" );
}
return returnIndex;
}
public static Object getTransformationName( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
try {
Object objTranName = Context.toString( actualObject.get( "_TransformationName_", actualObject ) );
return objTranName;
} catch ( Exception e ) {
throw Context.reportRuntimeError( e.toString() );
}
}
public static void appendToFile( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
if ( !isNull( ArgList ) && !isUndefined( ArgList ) ) {View on GitHub (pinned to f3058517a1)