{"record":{"id":"1dc9e32b94423c3e","repo":"pentaho/pentaho-kettle","slug":"can-t-specify-a-different-sorting-function-in-a-sorted-list","errorCode":null,"errorMessage":"Can't specify a different sorting function in a sorted list.","messagePattern":"Can't specify a different sorting function 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":127,"sourceCode":"      return this.__comparer;\n    },\n\n    set comparer(comparer) {\n      var hasOwn = O.hasOwn(this, \"__comparer\");\n      if(hasOwn && this.__comparer !== comparer || !hasOwn && comparer != null) {\n        if(comparer == null) {\n          delete this.__comparer;\n        } else {\n          this.__comparer = comparer;\n        }\n\n        this.sort();\n      }\n    },\n\n    sort: function(comparer) {\n      if(comparer != null && comparer !== this.__comparer) {\n        throw new Error(\"Can't specify a different sorting function in a sorted list.\");\n      }\n\n      this.base(this.__comparer);\n    },\n\n    /**\n     * Performs a binary search on the sorted list.\n     *\n     * @param {*} elem The item to search for.\n     *\n     * @return {number} The index of the element;\n     *                  when not found returns the negative\n     *                  index of the closest element.\n     */\n    search: function(elem) {\n      var left = 0;\n      var right = this.length - 1;\n","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/core-ui/src/main/resources/app/pentaho/lang/SortedList.js#L109-L145","documentation":"SortedList.sort overrides the base List.sort to keep the list ordered by its fixed comparer; passing a comparer argument that differs from the list's own __comparer is rejected. A sorted list's ordering is an invariant, so callers may only re-sort with the same comparer.","triggerScenarios":"sortedList.sort(myComparer) where myComparer is a different function reference than the one the list was created with (note: any comparer !== __comparer throws, even functionally identical ones); also sort(null/undefined) is fine, only non-null different comparers throw.","commonSituations":"Copying List code (which accepts a comparer) onto a SortedList; passing an inline arrow function that is semantically identical but a new reference; trying to change sort order at runtime.","solutions":["Call sort() with no arguments to re-sort with the list's own comparer","Create a new SortedList with the desired comparer instead of re-sorting an existing one","Use a plain List if you need to swap comparers dynamically"],"exampleFix":"// before\nsortedList.sort(function(a, b) { return a.name.localeCompare(b.name); }); // throws\n// after\nsortedList.sort(); // uses the list's own comparer","handlingStrategy":"type-guard","validationCode":"if (comparer != null && comparer !== list.__comparer) {\n  throw new TypeError('Cannot pass a different comparer to a SortedList');\n}\nlist.sort();","typeGuard":"function canSortWith(list, comparer) {\n  return comparer == null; // SortedList only accepts its own comparer\n}","tryCatchPattern":"try {\n  list.sort(cmp);\n} catch (e) {\n  if (String(e.message).indexOf('different sorting function') >= 0) {\n    list.sort(); // fall back to the list's own comparer\n  } else throw e;\n}","preventionTips":["Never pass a comparer argument when sorting a SortedList","Do not reuse List sort patterns on SortedList","Construct a new SortedList with a different comparer instead of re-sorting"],"tags":["sorted-list","sort","argument"],"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"}