{"record":{"id":"ea6de369e4842aa3","repo":"pentaho/pentaho-kettle","slug":"can-t-do-a-indexed-insert-in-a-sorted-list","errorCode":null,"errorMessage":"Can't do a indexed insert in a sorted list.","messagePattern":"Can't do a indexed insert in a sorted list\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugins/core-ui/src/main/resources/app/pentaho/lang/SortedList.js","lineNumber":179,"sourceCode":"      // 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\n    replace: function() {\n      throw new Error(\"Can't do a indexed replace in a sorted list.\");\n    },\n\n    splice: function() {\n      if(arguments.length > 2) {\n        throw new Error(\"Can't do a indexed insert in a sorted list.\");\n      }\n\n      this.base(arguments);\n    },\n","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/core-ui/src/main/resources/app/pentaho/lang/SortedList.js#L161-L197","documentation":"SortedList.unshift throws because inserting at index 0 (Array.prototype.unshift semantics) would violate the sorted order, which is determined solely by the comparer, not by caller-supplied positions. Positional insertion is only supported on unsorted lists.","triggerScenarios":"Any call to sortedList.unshift(...items); also triggered indirectly by code shared with List that prepends elements.","commonSituations":"Prepending a new item to a collection assuming Array/List behavior; porting List-based code to SortedList without auditing mutation calls.","solutions":["Use add(value) to insert the item; it is placed at the sorted position","Use addN([...]) to insert multiple items at once","Use a plain List if positional insertion is required"],"exampleFix":"// before\nsortedList.unshift(newValue); // throws\n// after\nsortedList.add(newValue); // inserted in sorted position","handlingStrategy":"type-guard","validationCode":"if (typeof list.unshift === 'function' && list.isSorted) {\n  throw new TypeError('unshift is unsupported on SortedList; use add');\n}","typeGuard":null,"tryCatchPattern":"try {\n  list.unshift(item);\n} catch (e) {\n  if (String(e.message).indexOf('indexed insert') >= 0) {\n    list.add(item);\n  } else throw e;\n}","preventionTips":["Always use add/addN on SortedList regardless of intended position","Never prepend items to sorted collections","Replace SortedList with List where positional insertion is a requirement"],"tags":["sorted-list","unsupported-operation","insert"],"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"}