{"record":{"id":"1ae4be8c64155d03","repo":"pentaho/pentaho-kettle","slug":"the-function-call-protectxmlcdata-requires-1-argument","errorCode":null,"errorMessage":"The function call protectXMLCDATA requires 1 argument.","messagePattern":"The function call protectXMLCDATA requires 1 argument\\.","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":2760,"sourceCode":"    }\n  }\n\n  public static String escapeSQL( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    if ( ArgList.length == 1 ) {\n      return Const.escapeSQL( Context.toString( ArgList[0] ) );\n    } else {\n      throw Context.reportRuntimeError( \"The function call escapeSQL requires 1 argument.\" );\n\n    }\n  }\n\n  public static String protectXMLCDATA( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    if ( ArgList.length == 1 ) {\n      return Const.protectXMLCDATA( Context.toString( ArgList[0] ) );\n    } else {\n      throw Context.reportRuntimeError( \"The function call protectXMLCDATA requires 1 argument.\" );\n\n    }\n  }\n\n  public static String removeDigits( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    if ( ArgList.length == 1 ) {\n      return Const.removeDigits( Context.toString( ArgList[0] ) );\n    } else {\n      throw Context.reportRuntimeError( \"The function call removeDigits requires 1 argument.\" );\n\n    }\n  }\n\n  public static String initCap( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    if ( ArgList.length == 1 ) {\n      return Const.initCap( Context.toString( ArgList[0] ) );","sourceCodeStart":2742,"sourceCodeEnd":2778,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L2742-L2778","documentation":"protectXMLCDATA wraps a string safely in CDATA using Const.protectXMLCDATA in the Modified Java Script Value step. This error is thrown when the function is invoked with an argument count other than exactly 1, as the wrapper handles a single string only.","triggerScenarios":"protectXMLCDATA() with zero arguments or protectXMLCDATA(s, x) with extra arguments; ArgList.length != 1 hits the else and throws.","commonSituations":"Users trying to pass a second option like 'alreadyWrapped'; scripts copied from other XML libraries with richer signatures.","solutions":["Call protectXMLCDATA with exactly one argument: protectXMLCDATA(text)","Remove extra options arguments; behavior is fixed by Const.protectXMLCDATA","Inspect the function help in the step's JS function tree"],"exampleFix":"// before\nvar cdata = protectXMLCDATA(text, true);\n// after\nvar cdata = protectXMLCDATA(text);","handlingStrategy":"validation","validationCode":"if (typeof text === 'string') { var cdata = protectXMLCDATA(text); }","typeGuard":"function isString(v){ return typeof v === 'string'; }","tryCatchPattern":"try { var cdata = protectXMLCDATA(text); } catch (e) { throw new Error('protectXMLCDATA requires exactly 1 argument: ' + e.message); }","preventionTips":["Call with a single string argument only","Check the function help in the step for supported signatures","Validate the field exists before use"],"tags":["javascript","xml","cdata","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"}