You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2020/02/10 02:30:00 UTC
[jira] [Closed] (GROOVY-9388) pop method does not output the latest
element of a sorted list
[ https://issues.apache.org/jira/browse/GROOVY-9388?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King closed GROOVY-9388.
-----------------------------
Resolution: Not A Problem
This was a breaking change we did in 2016 to align Groovy behavior with Java behavior as described in GROOVY-6396. It was listed in the breaking changes for the 2.5 release (bullet point 16):
https://groovy-lang.org/releasenotes/groovy-2.5.html#Groovy2.5releasenotes-Breakingchanges
If you treat something like a LinkedList as a stack and just use push and pop you won't notice any change. If you avoid using the stack operations for lists, you also won't notice any change. It was when combining list and stack operations that our behavior was different to Java and we decided to change to align them - otherwise code cut-n-pasted from Java had different semantics.
In your case, I'd suggest just using list operations, e.g. {{.last()}}.
> 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)