{"record":{"id":"cef69f3d0be7f85c","repo":"pentaho/pentaho-kettle","slug":"the-function-call-decode-requires-more-than-1-argument","errorCode":null,"errorMessage":"The function call decode requires more than 1 argument.","messagePattern":"The function call decode requires more than 1 argument\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1499,"sourceCode":"      if ( ArgList.length >= 2 ) {\n        if ( isNull( ArgList, new int[] { 0, 1 } ) ) {\n          return null;\n        } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {\n          return undefinedValue;\n        }\n        Object objToCompare = ArgList[0];\n        for ( int i = 1; i < ArgList.length - 1; i = i + 2 ) {\n          if ( ArgList[i].equals( objToCompare ) ) {\n            return ArgList[i + 1];\n          }\n        }\n        if ( ArgList.length % 2 == 0 ) {\n          return ArgList[ArgList.length - 1];\n        } else {\n          return objToCompare;\n        }\n      } else {\n        throw new RuntimeException( \"The function call decode requires more than 1 argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( \"The function call decode is not valid : \" + e.getMessage() );\n    }\n  }\n\n  public static String replace( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    try {\n      if ( ArgList.length >= 2 && ( ArgList.length - 1 ) % 2 == 0 ) {\n        if ( isNull( ArgList, new int[] { 0, 1 } ) ) {\n          return null;\n        } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {\n          return (String) undefinedValue;\n        }\n        String objForReplace = (String) ArgList[0];\n        for ( int i = 1; i < ArgList.length - 1; i = i + 2 ) {\n          objForReplace = objForReplace.replaceAll( (String) ArgList[i], (String) ArgList[i + 1] );","sourceCodeStart":1481,"sourceCodeEnd":1517,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1481-L1517","documentation":"decode mimics Oracle's DECODE: it compares the first argument against subsequent pairs and returns the matching value (or a trailing default). It requires more than one argument; if called with only one (just the value to compare), this RuntimeException is thrown.","triggerScenarios":"Calling decode(x) with a single argument in a JavaScript transformation step.","commonSituations":"Porting SQL DECODE expressions incorrectly, dropping the search/result pairs during refactoring.","solutions":["Call decode with at least 2 arguments: decode(value, pair-or-default...), e.g. decode(x, 'A', 1, 2).","Add the search/result pairs you intended to compare against.","If no pairs are needed, don't use decode at all - just use the value directly."],"exampleFix":"// before\nvar r = decode(status); // throws\n// after\nvar r = decode(status, 'A', 1, 'B', 2, 0);","handlingStrategy":"validation","validationCode":"function safeDecode() {\n  if (arguments.length < 2) return arguments[0];\n  return decode.apply(null, arguments);\n}","typeGuard":null,"tryCatchPattern":"try {\n  var r = decode(x, 'A', 1, 'B', 2, 0);\n} catch (e) {\n  var r = 0; // default when decode is unusable\n}","preventionTips":["Always provide at least one search/result pair or a default after the compared value.","Port Oracle DECODE expressions pair-by-pair.","If only one argument is needed, skip decode and use the value directly."],"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"}