{"record":{"id":"47055350d6218a83","repo":"pentaho/pentaho-kettle","slug":"can-t-copy-within-a-sorted-list","errorCode":null,"errorMessage":"Can't copy within a sorted list.","messagePattern":"Can't copy within a sorted list\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugins/core-ui/src/main/resources/app/pentaho/lang/SortedList.js","lineNumber":167,"sourceCode":"\n        var comparison = this.__comparer(this[i], elem);\n\n        if(comparison < 0) {\n          left = i + 1;\n        } else if(comparison > 0) {\n          right = i - 1;\n        } else {\n          return i;\n        }\n      }\n\n      // two's complement operation being used to\n      // return (x+1)*-1 in a hackish way\n      return ~left;\n    },\n\n    copyWithin: function() {\n      throw new Error(\"Can't copy within a sorted list.\");\n    },\n\n    fill: function() {\n      throw new Error(\"Can't fill a sorted list.\");\n    },\n\n    reverse: function() {\n      throw new Error(\"Can't reverse a sorted list.\");\n    },\n\n    unshift: function() {\n      throw new Error(\"Can't do a indexed insert in a sorted list.\");\n    },\n\n    insert: function() {\n      throw new Error(\"Can't do a indexed insert in a sorted list.\");\n    },\n","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/core-ui/src/main/resources/app/pentaho/lang/SortedList.js#L149-L185","documentation":"SortedList unconditionally throws from copyWithin because copying elements within the list without reordering them would break the sorted-order invariant. The method exists to satisfy the ECMAScript Array-prototype-like surface but is deliberately unsupported.","triggerScenarios":"Any call to sortedList.copyWithin(...) with any arguments; typically via generic array helpers or code written against List/Array semantics.","commonSituations":"Array-generic utilities applied to a sorted list; porting code from List to SortedList without auditing in-place mutation methods; trying to duplicate a range of elements.","solutions":["Rebuild a new list with the desired contents instead of copying in place","Convert to a plain array (toArray) and perform copyWithin there","Use a plain List if unsorted in-place manipulation is required"],"exampleFix":"// before\nsortedList.copyWithin(2, 0, 1); // throws\n// after\nvar arr = sortedList.toArray().copyWithin(2, 0, 1);","handlingStrategy":"try-catch","validationCode":"if (typeof list.copyWithin === 'function' && list.isSorted) {\n  throw new TypeError('copyWithin is unsupported on SortedList');\n}","typeGuard":null,"tryCatchPattern":"try {\n  list.copyWithin(2, 0, 1);\n} catch (e) {\n  if (String(e.message).indexOf('copy within a sorted list') >= 0) {\n    list = list.toArray().copyWithin(2, 0, 1); // operate on a plain array\n  } else throw e;\n}","preventionTips":["Audit array-generic helpers before applying them to SortedList instances","Treat copyWithin/fill/reverse/unshift/insert/replace as unsupported on SortedList","Materialize to a plain array when in-place position-based edits are needed"],"tags":["sorted-list","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}