{"record":{"id":"83f45d83e9ab66df","repo":"pentaho/pentaho-kettle","slug":"can-t-reverse-a-sorted-list","errorCode":null,"errorMessage":"Can't reverse a sorted list.","messagePattern":"Can't reverse a sorted list\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugins/core-ui/src/main/resources/app/pentaho/lang/SortedList.js","lineNumber":175,"sourceCode":"          return i;\n        }\n      }\n\n      // two's complement operation being used to\n      // return (x+1)*-1 in a hackish way\n      return ~left;\n    },\n\n    copyWithin: function() {\n      throw new Error(\"Can't copy within a sorted list.\");\n    },\n\n    fill: function() {\n      throw new Error(\"Can't fill a sorted list.\");\n    },\n\n    reverse: function() {\n      throw new Error(\"Can't reverse a sorted list.\");\n    },\n\n    unshift: function() {\n      throw new Error(\"Can't do a indexed insert in a sorted list.\");\n    },\n\n    insert: function() {\n      throw new Error(\"Can't do a indexed insert in a sorted list.\");\n    },\n\n    replace: function() {\n      throw new Error(\"Can't do a indexed replace in a sorted list.\");\n    },\n\n    splice: function() {\n      if(arguments.length > 2) {\n        throw new Error(\"Can't do a indexed insert in a sorted list.\");\n      }","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/core-ui/src/main/resources/app/pentaho/lang/SortedList.js#L157-L193","documentation":"Mutation guard on the SortedList prototype in the Pentaho client UI: reverse() was called on a list that maintains sort order invariantly. All order-destroying operations (copyWithin, fill, reverse, unshift, indexed insert) throw to preserve the sorted invariant.","triggerScenarios":"Any call to sortedList.reverse(), directly or via array-generic code that reverses in place.","commonSituations":"Trying to display a sorted list in descending order; porting List code to SortedList; array-generic helpers iterating/reversing collections.","solutions":["Iterate the list backwards instead of mutating it","Create a new SortedList with an inverted comparer for descending order","Copy to a plain array/Array and reverse that copy"],"exampleFix":"// before\nsortedList.reverse(); // throws\n// after\nfor (var i = sortedList.count - 1; i >= 0; i--) process(sortedList.at(i));","handlingStrategy":"try-catch","validationCode":"if (list.isSorted) {\n  throw new TypeError('reverse is unsupported on SortedList');\n}","typeGuard":null,"tryCatchPattern":"try {\n  list.reverse();\n} catch (e) {\n  if (String(e.message).indexOf('reverse a sorted list') >= 0) {\n    for (var i = list.count - 1; i >= 0; i--) process(list.at(i));\n  } else throw e;\n}","preventionTips":["Iterate backwards instead of reversing in place","Build a new SortedList with an inverted comparer for descending order","Convert to a plain array before reversing"],"tags":["sorted-list","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}