Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Not A Problem
-
2.5.8, 2.5.9
-
None
-
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))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))
Description
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.