pentaho/pentaho-kettle · error · Rhino runtime error
The function call getOcuranceString is not valid
Error message
The function call getOcuranceString is not valid
What it means
The JS function getOcuranceString(actualContext, actualObject, args...) wraps its work in a try/catch and, if the internal call to Const.getOcuranceString throws, reports a generic 'not valid' runtime error. This branch handles exceptions thrown during counting.
Solutions
- Ensure both arguments are plain strings before calling.
- Check that the search-for string is non-null.
- Wrap the call in a JS try/catch or coerce with String(...) first.
Example fix
// before
var n = getOcuranceString(row.getString('col'), null);
// after
var n = getOcuranceString(String(row.getString('col')), String(searchTerm)); Defensive patterns
Strategy: type-guard
Validate before calling
// JS
if (typeof s !== 'string' || typeof search !== 'string') throw new Error('getOcuranceString needs two strings'); Type guard
function isStr(v){ return typeof v === 'string'; } Try / catch
try { var n = getOcuranceString(String(s), String(search)); } catch (e) { /* handle */ } Prevention
- Coerce arguments with String() before calling JS helper functions.
- Avoid passing null/undefined row values directly.
When it happens
Trigger: getOcuranceString(string, searchFor) is called with 2+ arguments but evaluation of either argument or the count operation throws (e.g. a non-convertible Rhino object).
Common situations: Passing an object/undefined-ish value that Context.toString cannot convert, or a null returned from a previous script expression.
Understand the failure class
Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.
Related errors
- The function call removeCRLF is not valid
- Script.Log.CouldNotAddDefaultConstants
- The function call loadFileContentrequires 1 ou 2 arguments.
- Could not convert the given String :
- e.toString()
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/15e82681830e6ab9.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:2857
Function FunctionContext ) {
int nr = 0;
if ( ArgList.length == 2 ) {
try {
if ( isNull( ArgList[0] ) ) {
return 0;
} else if ( isUndefined( ArgList[0] ) ) {
return (Integer) Context.getUndefinedValue();
}
if ( isNull( ArgList[1] ) ) {
return 0;
} else if ( isUndefined( ArgList[1] ) ) {
return (Integer) Context.getUndefinedValue();
}
String string = Context.toString( ArgList[0] );
String searchFor = Context.toString( ArgList[1] );
nr = Const.getOcuranceString( string, searchFor );
} catch ( Exception e ) {
throw Context.reportRuntimeError( "The function call getOcuranceString is not valid" );
}
} else {
throw Context.reportRuntimeError( "The function call getOcuranceString is not valid" );
}
return nr;
}
public static String removeCRLF( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
if ( ArgList.length == 1 ) {
try {
if ( isNull( ArgList[0] ) ) {
return null;
} else if ( isUndefined( ArgList[0] ) ) {
return (String) Context.getUndefinedValue();
}
return Const.removeCRLF( Context.toString( ArgList[0] ) );View on GitHub (pinned to f3058517a1)