pentaho/pentaho-kettle · error · Error
Can't specify a different sorting function in a sorted list.
Error message
Can't specify a different sorting function in a sorted list.
What it means
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.
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
Example fix
// before
sortedList.sort(function(a, b) { return a.name.localeCompare(b.name); }); // throws
// after
sortedList.sort(); // uses the list's own comparer Defensive patterns
Strategy: type-guard
Validate before calling
if (comparer != null && comparer !== list.__comparer) {
throw new TypeError('Cannot pass a different comparer to a SortedList');
}
list.sort(); Type guard
function canSortWith(list, comparer) {
return comparer == null; // SortedList only accepts its own comparer
} Try / catch
try {
list.sort(cmp);
} catch (e) {
if (String(e.message).indexOf('different sorting function') >= 0) {
list.sort(); // fall back to the list's own comparer
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Can't copy within a sorted list.
- Can't do a indexed insert in a sorted list.
- Can't do a indexed replace in a sorted list.
- Can't fill a sorted list.
- Can't reverse a sorted list.
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/1dc9e32b94423c3e.
Report an issue: GitHub.
Appendix: source
Thrown at plugins/core-ui/src/main/resources/app/pentaho/lang/SortedList.js:127
return this.__comparer;
},
set comparer(comparer) {
var hasOwn = O.hasOwn(this, "__comparer");
if(hasOwn && this.__comparer !== comparer || !hasOwn && comparer != null) {
if(comparer == null) {
delete this.__comparer;
} else {
this.__comparer = comparer;
}
this.sort();
}
},
sort: function(comparer) {
if(comparer != null && comparer !== this.__comparer) {
throw new Error("Can't specify a different sorting function in a sorted list.");
}
this.base(this.__comparer);
},
/**
* Performs a binary search on the sorted list.
*
* @param {*} elem The item to search for.
*
* @return {number} The index of the element;
* when not found returns the negative
* index of the closest element.
*/
search: function(elem) {
var left = 0;
var right = this.length - 1;
View on GitHub (pinned to f3058517a1)