{"record":{"id":"15e82681830e6ab9","repo":"pentaho/pentaho-kettle","slug":"the-function-call-getocurancestring-is-not-valid","errorCode":null,"errorMessage":"The function call getOcuranceString is not valid","messagePattern":"The function call getOcuranceString is not valid","errorType":"exception","errorClass":"Rhino runtime error","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":2857,"sourceCode":"    Function FunctionContext ) {\n    int nr = 0;\n    if ( ArgList.length == 2 ) {\n      try {\n        if ( isNull( ArgList[0] ) ) {\n          return 0;\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return (Integer) Context.getUndefinedValue();\n        }\n        if ( isNull( ArgList[1] ) ) {\n          return 0;\n        } else if ( isUndefined( ArgList[1] ) ) {\n          return (Integer) Context.getUndefinedValue();\n        }\n        String string = Context.toString( ArgList[0] );\n        String searchFor = Context.toString( ArgList[1] );\n        nr = Const.getOcuranceString( string, searchFor );\n      } catch ( Exception e ) {\n        throw Context.reportRuntimeError( \"The function call getOcuranceString is not valid\" );\n      }\n    } else {\n      throw Context.reportRuntimeError( \"The function call getOcuranceString is not valid\" );\n    }\n    return nr;\n  }\n\n  public static String removeCRLF( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    if ( ArgList.length == 1 ) {\n      try {\n        if ( isNull( ArgList[0] ) ) {\n          return null;\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return (String) Context.getUndefinedValue();\n        }\n\n        return Const.removeCRLF( Context.toString( ArgList[0] ) );","sourceCodeStart":2839,"sourceCodeEnd":2875,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L2839-L2875","documentation":"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.","triggerScenarios":"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).","commonSituations":"Passing an object/undefined-ish value that Context.toString cannot convert, or a null returned from a previous script expression.","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."],"exampleFix":"// before\nvar n = getOcuranceString(row.getString('col'), null);\n// after\nvar n = getOcuranceString(String(row.getString('col')), String(searchTerm));","handlingStrategy":"type-guard","validationCode":"// JS\nif (typeof s !== 'string' || typeof search !== 'string') throw new Error('getOcuranceString needs two strings');","typeGuard":"function isStr(v){ return typeof v === 'string'; }","tryCatchPattern":"try { var n = getOcuranceString(String(s), String(search)); } catch (e) { /* handle */ }","preventionTips":["Coerce arguments with String() before calling JS helper functions.","Avoid passing null/undefined row values directly."],"tags":["javascript","kettle","rhino","argument"],"backgroundTag":"invalid-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"}