{"record":{"id":"0ecd48c4112330bd","repo":"pentaho/pentaho-kettle","slug":"unable-to-create-a-row-copy","errorCode":null,"errorMessage":"Unable to create a row copy: ","messagePattern":"Unable to create a row copy: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1913,"sourceCode":"      }\n    } else {\n      throw new RuntimeException( \"The function call getInputRowMeta doesn't require arguments.\" );\n    }\n  }\n\n  // Return the input row metadata\n  public static Object[] createRowCopy( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    if ( ArgList.length == 1 ) {\n      try {\n        int newSize = (int) Math.round( (Double) ArgList[0] );\n\n        Object scmO = actualObject.get( \"row\" );\n        Object[] row = (Object[]) scmO; // TODO AKRETION ensure\n\n        return RowDataUtil.createResizedCopy( row, newSize );\n      } catch ( Exception e ) {\n        throw new RuntimeException( \"Unable to create a row copy: \" + Const.CR + e.toString() );\n      }\n    } else {\n      throw new RuntimeException(\n        \"The function call createRowCopy requires a single arguments : the new size of the row\" );\n    }\n  }\n\n  // put a row out to the next steps...\n  //\n  public static void putRow( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    if ( ArgList.length == 1 ) {\n      try {\n        Object[] newRow = (Object[]) ArgList[0];\n\n        Object scmO = actualObject.get( \"_step_\" );\n        try {\n          Script step = (Script) scmO;","sourceCodeStart":1895,"sourceCodeEnd":1931,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1895-L1931","documentation":"Thrown by the createRowCopy added function exposed to Script transform scripts. After reading the 'row' variable from the script bindings and resizing it via RowDataUtil.createResizedCopy, any failure (bad row binding, cast failure, resize error) is wrapped in a RuntimeException with this message.","triggerScenarios":"Calling createRowCopy(newSize) in a script where (a) the bound 'row' object is not an Object[] (ClassCastException on the cast), (b) 'row' is missing/null, or (c) RowDataUtil.createResizedCopy fails for the requested size.","commonSituations":"Scripts written for a different step type where 'row' is not bound as Object[], calling createRowCopy before any row exists, or passing a non-integer/new negative size that breaks the resize.","solutions":["Check the wrapped cause (text after Const.CR) — a ClassCastException means the bound 'row' is not Object[]; fix the script/step context.","Ensure createRowCopy is only called while processing an actual incoming row so 'row' is populated.","Pass a single positive integer as the new row size.","If you only need to append fields, use the script transform's normal output-field mechanism instead of manually resizing the row."],"exampleFix":"// before\nvar newRow = createRowCopy(rowSizeFromVariable);\n// after\nvar newRow = createRowCopy(3); // exact integer size required","handlingStrategy":"try-catch","validationCode":"if (typeof row === 'undefined' || row === null) throw new Error('row binding not available');\nif (typeof newSize !== 'number' || newSize <= 0) throw new Error('createRowCopy needs a positive integer size');","typeGuard":"function isObjectArray(x) { return x != null && Object.prototype.toString.call(x) === '[object Array]'; }","tryCatchPattern":"try {\n  var newRow = createRowCopy(2);\n} catch (e) {\n  if (String(e).indexOf('Unable to create a row copy') !== -1) {\n    // check cause: likely 'row' not Object[] or invalid size\n  } else { throw e; }\n}","preventionTips":["Call createRowCopy only while processing an actual row","Pass exactly one positive integer size","Verify the step binds 'row' as Object[] (correct transform type)","Prefer the transform's field definitions over manual row resizing"],"tags":["pdi","kettle","script","row-copy","runtime"],"backgroundTag":"invalid-argument-value","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"}