{"record":{"id":"e7069e2f8820a9ad","repo":"pentaho/pentaho-kettle","slug":"the-function-call-setenvironmentvar-requires-2-arguments","errorCode":null,"errorMessage":"The function call setEnvironmentVar requires 2 arguments.","messagePattern":"The function call setEnvironmentVar 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":1555,"sourceCode":"\n    return \"\";\n  }\n\n  // Setting EnvironmentVar\n  public static void setEnvironmentVar( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    String sArg1 = \"\";\n    String sArg2 = \"\";\n    if ( ArgList.length == 2 ) {\n      try {\n        sArg1 = (String) ArgList[0];\n        sArg2 = (String) ArgList[1];\n        System.setProperty( sArg1, sArg2 );\n      } catch ( Exception e ) {\n        throw new RuntimeException( e.toString() );\n      }\n    } else {\n      throw new RuntimeException( \"The function call setEnvironmentVar requires 2 arguments.\" );\n    }\n  }\n\n  // Returning EnvironmentVar\n  public static String getEnvironmentVar( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    String sRC = \"\";\n    if ( ArgList.length == 1 ) {\n      try {\n        String sArg1 = (String) ArgList[0];\n        sRC = System.getProperty( sArg1, \"\" );\n      } catch ( Exception e ) {\n        sRC = \"\";\n      }\n    } else {\n      throw new RuntimeException( \"The function call getEnvironmentVar requires 1 argument.\" );\n    }\n    return sRC;","sourceCodeStart":1537,"sourceCodeEnd":1573,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1537-L1573","documentation":"Arity guard for setEnvironmentVar in the script step: the function was invoked without exactly two arguments (name, value). Any count other than 2 falls into the else-branch and throws, because System.setProperty needs exactly one key and one value.","triggerScenarios":"Calling setEnvironmentVar(name) with one argument, or with three or more arguments, in a JavaScript transformation step.","commonSituations":"Forgetting the value argument, attempting to set several variables in one call, refactoring typos.","solutions":["Call setEnvironmentVar(name, value) with exactly two String arguments.","Split multiple variables into separate calls.","Coerce values with String(...) to avoid the companion e.toString() error."],"exampleFix":"// before\nsetEnvironmentVar('MY_VAR'); // throws\n// after\nsetEnvironmentVar('MY_VAR', 'myValue');","handlingStrategy":"validation","validationCode":"function safeSetEnv(name, value) {\n  if (arguments.length !== 2) throw new Error('setEnvironmentVar requires exactly 2 arguments');\n  setEnvironmentVar(name, value);\n}","typeGuard":null,"tryCatchPattern":"try {\n  setEnvironmentVar(name, value);\n} catch (e) {\n  if (String(e.message).indexOf('requires 2 arguments') >= 0) {\n    // fix the call site arity\n  }\n}","preventionTips":["Always pass exactly two arguments: name and value.","Set each variable in its own call.","Fix arity errors at the call site rather than catching and swallowing."],"tags":["java","pdi","scripting","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"}