{"record":{"id":"a28c7c71e212d4d6","repo":"pentaho/pentaho-kettle","slug":"can-t-do-a-indexed-replace-in-a-sorted-list","errorCode":null,"errorMessage":"Can't do a indexed replace in a sorted list.","messagePattern":"Can't do a indexed replace 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":187,"sourceCode":"\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\n    __insertInOrder: function(elem, keyArgs) {\n      var elem2 = this._adding(elem, null, keyArgs);\n\n      if(elem2 !== undefined) {\n        var index = this.search(elem2);\n        if(index < 0) {\n          index = ~index;\n        } else {","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/core-ui/src/main/resources/app/pentaho/lang/SortedList.js#L169-L205","documentation":"SortedList.replace throws because replacing the element at a given index with an arbitrary value would place a value at a position not dictated by the comparer, breaking sorted order. Note splice with insert arguments (length > 2) also routes into this same error.","triggerScenarios":"Any call to sortedList.replace(value, index); also sortedList.splice(start, deleteCount, ...items) with more than 2 arguments, i.e. any splice that inserts items.","commonSituations":"Swapping an element in place with a new value; porting List code; using splice to replace/insert items in a sorted collection.","solutions":["Remove the old value (remove/removeAt) and add(value) the new one so order is maintained","Use splice(start, deleteCount) with no insert items if only removal is needed","Use a plain List if indexed replacement is required"],"exampleFix":"// before\nsortedList.replace(newValue, 2); // throws\n// after\nsortedList.removeAt(2);\nsortedList.add(newValue);","handlingStrategy":"type-guard","validationCode":"if (list.isSorted) {\n  throw new TypeError('indexed replace is unsupported on SortedList; remove+add instead');\n}","typeGuard":null,"tryCatchPattern":"try {\n  list.replace(newValue, idx);\n} catch (e) {\n  if (String(e.message).indexOf('indexed replace') >= 0) {\n    list.removeAt(idx); list.add(newValue);\n  } else throw e;\n}","preventionTips":["Model replacement on sorted collections as removeAt + add","Never call splice with more than 2 arguments on a SortedList","Review ported List code for replace/splice-with-inserts calls"],"tags":["sorted-list","unsupported-operation","replace"],"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"}