pentaho/pentaho-kettle · error · Error

Can't do a indexed replace in a sorted list.

Error message

Can't do a indexed replace in a sorted list.

What it means

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.

Solutions

  1. Remove the old value (remove/removeAt) and add(value) the new one so order is maintained
  2. Use splice(start, deleteCount) with no insert items if only removal is needed
  3. Use a plain List if indexed replacement is required

Example fix

// before
sortedList.replace(newValue, 2); // throws
// after
sortedList.removeAt(2);
sortedList.add(newValue);
Defensive patterns

Strategy: type-guard

Validate before calling

if (list.isSorted) {
  throw new TypeError('indexed replace is unsupported on SortedList; remove+add instead');
}

Try / catch

try {
  list.replace(newValue, idx);
} catch (e) {
  if (String(e.message).indexOf('indexed replace') >= 0) {
    list.removeAt(idx); list.add(newValue);
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Swapping an element in place with a new value; porting List code; using splice to replace/insert items in a sorted collection.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/a28c7c71e212d4d6. Report an issue: GitHub.

Appendix: source

Thrown at plugins/core-ui/src/main/resources/app/pentaho/lang/SortedList.js:187

    fill: function() {
      throw new Error("Can't fill a sorted list.");
    },

    reverse: function() {
      throw new Error("Can't reverse a sorted list.");
    },

    unshift: function() {
      throw new Error("Can't do a indexed insert in a sorted list.");
    },

    insert: function() {
      throw new Error("Can't do a indexed insert in a sorted list.");
    },

    replace: function() {
      throw new Error("Can't do a indexed replace in a sorted list.");
    },

    splice: function() {
      if(arguments.length > 2) {
        throw new Error("Can't do a indexed insert in a sorted list.");
      }

      this.base(arguments);
    },

    __insertInOrder: function(elem, keyArgs) {
      var elem2 = this._adding(elem, null, keyArgs);

      if(elem2 !== undefined) {
        var index = this.search(elem2);
        if(index < 0) {
          index = ~index;
        } else {

View on GitHub (pinned to f3058517a1)