pentaho/pentaho-kettle · error · Error

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

Error message

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

What it means

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.

Solutions

  1. Use add(value) to insert the item; it is placed at the sorted position
  2. Use addN([...]) to insert multiple items at once
  3. Use a plain List if positional insertion is required

Example fix

// before
sortedList.unshift(newValue); // throws
// after
sortedList.add(newValue); // inserted in sorted position
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof list.unshift === 'function' && list.isSorted) {
  throw new TypeError('unshift is unsupported on SortedList; use add');
}

Try / catch

try {
  list.unshift(item);
} catch (e) {
  if (String(e.message).indexOf('indexed insert') >= 0) {
    list.add(item);
  } else throw e;
}

Prevention

When it happens

Trigger: Any call to sortedList.unshift(...items); also triggered indirectly by code shared with List that prepends elements.

Common situations: Prepending a new item to a collection assuming Array/List behavior; porting List-based code to SortedList without auditing mutation calls.

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/ea6de369e4842aa3. Report an issue: GitHub.

Appendix: source

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

      // two's complement operation being used to
      // return (x+1)*-1 in a hackish way
      return ~left;
    },

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

    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);
    },

View on GitHub (pinned to f3058517a1)