Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7986

Map sort gives an error : Comparison method violates its general contract!

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3.10, 2.4.6
    • Fix Version/s: 2.4.7
    • Component/s: Groovy Console
    • Labels:

      Description

      Trying to sort of a map gives an error.
      Code

      usersPredictions = [guest697:[4, 10], guest809:[1, 6], guest993:[3, 6], guest785:[4, 15], guest893:[6, 6], guest399:[1, 6], guest206:[1, 7], guest202:[5, 7], admin:[4, 3], guest285:[1, 3], flo:[8, 52], guest753:[2, 3], guest635:[4, 3], guest754:[3, 11], guest024:[0, 4], guest971:[0, 5], guest824:[0, 6], guest295:[0, 6], guest421:[0, 6], guest389:[0, 6], guest095:[0, 7], guest000:[0, 6], guest430:[0,6], guest985:[0, 6], guest618:[0, 6], guest108:[0, 10], guest820:[0, 6], guest586:[0, 10], guest959:[0, 6], guest525:[0, 4], guest191:[0, 4], guest567:[0, 4], guest780:[0, 4], guest704:[0, 4], guest263:[0, 4], guest212:[0, 4], guest576:[0,4], guest494:[0, 4], guest378:[0, 4], guest589:[0, 4], guest507:[0, 4], guest580:[0, 4], guest396:[0, 4], guest879:[0, 4], guest647:[0, 4], guest128:[0, 4], guest234:[0, 10], guest040:[0, 4], guest510:[0, 10], guest583:[0, 4], guest247:[0,4], guest500:[0, 4], guest055:[0, 4], guest322:[0, 4], guest972:[0, 4], guest522:[0, 4], guest207:[0, 4], guest348:[0, 4], guest020:[0, 4], guest621:[0, 4], guest981:[0, 4], guest939:[0, 4], guest280:[0, 4], guest827:[0, 4], guest671:[0, 4], guest317:[0, 4], guest859:[0, 4], guest456:[0, 5], guest731:[0, 5], guest738:[0, 5], guest076:[0, 5], guest713:[0, 5], guest652:[0, 5], guest693:[0, 5], guest330:[0, 11], guest760:[0, 5], guest935:[0, 5], guest370:[0, 5], guest148:[0, 5], guest806:[0, 5], guest302:[0, 5], guest438:[0, 5], guest769:[0, 5], guest775:[0, 5], guest845:[0, 5], guest730:[0, 6], guest405:[0, 3], guest955:[0, 5], guest819:[0, 3], guest732:[0, 3], guest440:[0, 3], guest104:[0, 3], guest155:[0, 4], guest219:[0, 5], guest070:[0, 3], guest490:[0, 5], guest764:[0, 6], guest442:[0,6], guest067:[0, 6], guest185:[0, 6], guest484:[0, 6], guest739:[0, 6], guest073:[0, 6], guest179:[0, 6], guest275:[0, 6], guest631:[0, 6], guest755:[0, 6], guest221:[0, 6], guest232:[0, 6], guest152:[0, 6], guest485:[0, 6], guest911:[0, 6], guest925:[0, 6], guest626:[0, 6], guest675:[0, 3], guest457:[0, 4], guest923:[0, 4], guest605:[0, 3], guest624:[0, 4]]
      println usersPredictions.sort {it.value}
      

      Error:

      Caught: java.lang.IllegalArgumentException: Comparison method violates its general contract!
      java.lang.IllegalArgumentException: Comparison method violates its general contract!
      	at indent.run(indent.groovy:124)
      

      Removing some of the values - resolves the issue. In Online groovy console and version 1.8.6 this code is working without error.

        Attachments

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              victus victus victusian
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: