{"record":{"id":"5cb832f126587bac","repo":"pentaho/pentaho-kettle","slug":"scriptvaluesmod-log-couldnotadddefaultfunctions","errorCode":null,"errorMessage":"ScriptValuesMod.Log.CouldNotAddDefaultFunctions","messagePattern":"ScriptValuesMod\\.Log\\.CouldNotAddDefaultFunctions","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesMod.java","lineNumber":274,"sourceCode":"            for ( int i = 0; i < meta.getAddClasses().length; i++ ) {\n              Object jsOut = Context.javaToJS( meta.getAddClasses()[ i ].getAddObject(), data.scope );\n              ScriptableObject.putProperty( data.scope, meta.getAddClasses()[ i ].getJSName(), jsOut );\n            }\n          }\n        } catch ( Exception e ) {\n          throw new KettleValueException( BaseMessages.getString(\n            PKG, \"ScriptValuesMod.Log.CouldNotAttachAdditionalScripts\" ), e );\n        }\n\n        // Adding some default JavaScriptFunctions to the System\n        try {\n          Context.javaToJS( ScriptValuesAddedFunctions.class, data.scope );\n          ( (ScriptableObject) data.scope ).defineFunctionProperties(\n            ScriptValuesAddedFunctions.jsFunctionList, ScriptValuesAddedFunctions.class,\n            ScriptableObject.DONTENUM );\n        } catch ( Exception ex ) {\n          // System.out.println(ex.toString());\n          throw new KettleValueException( BaseMessages.getString(\n            PKG, \"ScriptValuesMod.Log.CouldNotAddDefaultFunctions\" ), ex );\n        }\n\n        // Adding some Constants to the JavaScript\n        try {\n\n          data.scope.put( \"SKIP_TRANSFORMATION\", data.scope, Integer.valueOf( SKIP_TRANSFORMATION ) );\n          data.scope.put( \"ABORT_TRANSFORMATION\", data.scope, Integer.valueOf( ABORT_TRANSFORMATION ) );\n          data.scope.put( \"ERROR_TRANSFORMATION\", data.scope, Integer.valueOf( ERROR_TRANSFORMATION ) );\n          data.scope.put( \"CONTINUE_TRANSFORMATION\", data.scope, Integer.valueOf( CONTINUE_TRANSFORMATION ) );\n\n        } catch ( Exception ex ) {\n          // System.out.println(\"Exception Adding the Constants \" + ex.toString());\n          throw new KettleValueException( BaseMessages.getString(\n            PKG, \"ScriptValuesMod.Log.CouldNotAddDefaultConstants\" ), ex );\n        }\n\n        try {","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesMod.java#L256-L292","documentation":"After attaching user scripts, addValues() exposes Pentaho's built-in helper functions by calling Context.javaToJS(ScriptValuesAddedFunctions.class, ...) and defineFunctionProperties(jsFunctionList, ...) on the scope; any Exception is rethrown as KettleValueException with message ScriptValuesMod.Log.CouldNotAddDefaultFunctions. This indicates the standard script function library could not be registered, so built-in functions would be unavailable.","triggerScenarios":"Context.javaToJS on ScriptValuesAddedFunctions.class or ((ScriptableObject) data.scope).defineFunctionProperties(ScriptValuesAddedFunctions.jsFunctionList, ScriptValuesAddedFunctions.class, DONTENUM) throws — typically because data.scope is not a ScriptableObject, the Rhino version's reflection of jsFunctionList fails, or method signature checks in defineFunctionProperties reject entries.","commonSituations":"Rhino version mismatch (custom/updated rhino jar on the classpath replacing the one Pentaho expects, so function-list reflection or method signatures differ); scope initialized in a way that yields a plain (non-ScriptableObject) object; corrupted/partial plugin install where ScriptValuesAddedFunctions class is from an incompatible plugin version.","solutions":["Check the cause stack trace ('ex') in the log to see whether the failure is in javaToJS or defineFunctionProperties.","Verify the rhino jar on the classpath matches the one shipped with your Pentaho version; remove any manually upgraded rhino jar.","Reinstall/refresh the scriptvalues_mod plugin so ScriptValuesAddedFunctions matches the step's expected version.","Confirm data.scope comes from cx.initStandardObjects (a ScriptableObject) and was not replaced by custom scope code.","If you patched ScriptValuesAddedFunctions, ensure every method listed in jsFunctionList keeps the exact static signature Rhino requires (public static, Context/Scriptable args)."],"exampleFix":"// before: custom newer rhino.jar placed in lib/ overriding Pentaho's bundled version\nlib/rhino-1.7.15-custom.jar\n// after: restore the bundled version\nlib/rhino-<pentaho-bundled-version>.jar","handlingStrategy":"try-catch","validationCode":"// Java, sanity-check the script environment before executing the transformation\nif (!(data.scope instanceof ScriptableObject))\n  throw new IllegalStateException(\"JS scope is not a ScriptableObject; initStandardObjects failed\");\nClass.forName(\"org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions\");\n// also verify no conflicting rhino jar: check ProtectionDomain of Context class","typeGuard":null,"tryCatchPattern":"try {\n  transformation.execute(params);\n} catch (KettleValueException e) {\n  if (e.getMessage().contains(\"CouldNotAddDefaultFunctions\")) {\n    log.error(\"Default function registration failed: \" + e.getCause(), e.getCause());\n    // check rhino jar version / plugin install, then retry\n  } else { throw e; }\n}","preventionTips":["Do not replace Pentaho's bundled rhino jar with a different version on the classpath.","Reinstall the script step plugin if Pentaho was partially upgraded.","If extending ScriptValuesAddedFunctions, keep every jsFunctionList entry's static signature exactly as Rhino's defineFunctionProperties expects.","Confirm scope creation via cx.initStandardObjects so it is a ScriptableObject."],"tags":["kettle","pentaho","rhino","script-engine","dependency-version"],"backgroundTag":"module-init-failed","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"}