You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "René Ribaud (Jira)" <ji...@apache.org> on 2020/02/09 21:57:00 UTC

[jira] [Created] (GROOVY-9388) pop method does not output the latest element of a sorted list

René Ribaud created GROOVY-9388:
-----------------------------------

             Summary: pop method does not output the latest element of a sorted list
                 Key: GROOVY-9388
                 URL: https://issues.apache.org/jira/browse/GROOVY-9388
             Project: Groovy
          Issue Type: Bug
          Components: groovy-runtime
    Affects Versions: 2.5.9, 2.5.8
         Environment: import groovy.json.JsonSlurper

def hd = '''
{
  "records": {
    "integration": {
      "log-manager-curator": {
        "images": [
          {
            "name": "decofer-log-manager-curator:00.20.00-build8",
            "tag": "",
            "timestamp": "2019-12-17T11:32:50+0000"
          },
          {
            "name": "decofer-log-manager-curator:00.20.00-build9",
            "tag": "",
            "timestamp": "2019-12-17T13:13:19+0000"
          },
          {
            "name": "decofer-log-manager-curator:00.20.00-build43",
            "tag": "",
            "timestamp": "2019-12-19T16:06:56+0000"
          },
          {
            "name": "decofer-log-manager-curator:00.20.00-build43",
            "tag": "",
            "timestamp": "2019-12-19T16:32:18+0000"
          },
          {
            "name": "decofer-log-manager-curator:00.20.00-build43",
            "tag": "",
            "timestamp": "2019-12-20T06:47:02+0000"
          },
          {
            "name": "decofer-log-manager-curator:00.20.00-build43",
            "tag": "",
            "timestamp": "2020-01-16T05:18:46+0000"
          },
          {
            "name": "decofer-log-manager-curator:00.20.00-build43",
            "tag": "",
            "timestamp": "2020-01-17T05:20:11+0000"
          },
          {
            "name": "decofer-log-manager-curator:00.20.00-build43",
            "tag": "",
            "timestamp": "2020-01-21T08:04:16+0000"
          },
          {
            "name": "decofer-log-manager-curator:00.20.00-build43",
            "tag": "",
            "timestamp": "2020-01-24T05:22:16+0000"
          },
          {
            "name": "decofer-log-manager-curator:00.20.00-build43",
            "tag": "",
            "timestamp": "2020-01-29T14:55:24+0000"
          },
          {
            "name": "decofer-log-manager-curator:00.20.00-build43",
            "tag": "",
            "timestamp": "2020-01-29T15:40:22+0000"
          }
        ]
      }
    }
  }
}'''

def jsonSlurper = new JsonSlurper()
def object = jsonSlurper.parseText(hd)

println "My full object"
println "--------------"
println object
println ""

def retrieveLastImage(Map historyData){
    def images = []
    try {
        historyData["records"]["integration"]["log-manager-curator"]["images"].each() { image -> images.add(image["name"]) }
    }
    catch (java.lang.NullPointerException e){
        return ""
    }
    List sorted = images.sort()
    println "List sorted"
    println "-----------"
    println sorted
    println ""
    println "Last list element inside function"
    println "---------------------------------"
    println sorted.pop()
    return images.sort().pop()
}

println ""
println("Last element outside function:" + retrieveLastImage(object))
            Reporter: René Ribaud
             Fix For: 2.4.8
         Attachments: Screenshot from 2020-01-30 19-26-36.png

Hello,

Latest stable version of Groovy looks to have an important regression.

list.sort().pop() looks to not provide the latest element of a sorted list.

Please look at the code inside "Environment field" and *screenshot* showing the result and difference between versions.

2.4.8 seems to work fine.

2.5.9 is completely broken.

So far I have not checked all impacted versions.

 

Sorry if this bug has already been reported, but I did not find any reference to a similar issue elswhere.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)