pentaho/pentaho-kettle · error · Error

Can't copy within a sorted list.

Error message

Can't copy within a sorted list.

What it means

SortedList unconditionally throws from copyWithin because copying elements within the list without reordering them would break the sorted-order invariant. The method exists to satisfy the ECMAScript Array-prototype-like surface but is deliberately unsupported.

Solutions

  1. Rebuild a new list with the desired contents instead of copying in place
  2. Convert to a plain array (toArray) and perform copyWithin there
  3. Use a plain List if unsorted in-place manipulation is required

Example fix

// before
sortedList.copyWithin(2, 0, 1); // throws
// after
var arr = sortedList.toArray().copyWithin(2, 0, 1);
Defensive patterns

Strategy: try-catch

Validate before calling

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

Try / catch

try {
  list.copyWithin(2, 0, 1);
} catch (e) {
  if (String(e.message).indexOf('copy within a sorted list') >= 0) {
    list = list.toArray().copyWithin(2, 0, 1); // operate on a plain array
  } else throw e;
}

Prevention

When it happens

Trigger: Any call to sortedList.copyWithin(...) with any arguments; typically via generic array helpers or code written against List/Array semantics.

Common situations: Array-generic utilities applied to a sorted list; porting code from List to SortedList without auditing in-place mutation methods; trying to duplicate a range of elements.

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

Appendix: source

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

        var comparison = this.__comparer(this[i], elem);

        if(comparison < 0) {
          left = i + 1;
        } else if(comparison > 0) {
          right = i - 1;
        } else {
          return i;
        }
      }

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

View on GitHub (pinned to f3058517a1)