[ 
https://issues.apache.org/jira/browse/GROOVY-9388?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17163547#comment-17163547
 ] 

Christopher Rudolf edited comment on GROOVY-9388 at 7/23/20, 1:06 PM:
----------------------------------------------------------------------

I think it should be more obvious *which* methods have been changed.

Currently I found ".pop()" should be replaced with ".removeLast()" and 
".push(..)" with ".add(..)". 

I think that the ConfigSlurper/JsonSlurper therefore is broken in 2.5.6, 
because it was not adjusted.


was (Author: crudolf):
I think it should be more obvious *which* methods have been changed.

Currently I found ".pop()" should be replaced with ".removeLast()" and 
".push(..)" with ".add(..)". 

I think that the ConfigSlurper/JsonSlurper therefore is broken in 2.5.8, 
because it was not adjusted.

> 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.8, 2.5.9
>         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
>            Priority: Critical
>             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)

Reply via email to