jenkinsci / jenkinsci/workflow-cps-plugin

[JENKINS-50863] list.empty broken in pipeline scripts

Open
#1,441 5 comments 0 reactions 0 assignees View on GitHub
component:workflow-cps-plugin imported-jira-issue priority:minor regression resolution:unresolved
Dominant language
Java
Stars
186
Forks
213
Avg merge
12h 12m
Merged PRs (30d)
8

Description

Since upgrading to Pipeline:Groovy 2.48, the .empty property of List objects gives very strange results, whose boolean value in particular is the reverse of the expected.

When executing the following script as a pipeline (testet via "Replay" and replacing the existing script by this) gives weird output:


 Script

x = [] as List

println x
println x.isEmpty()
println x.empty
x<<"hello"
println x
println x.isEmpty()
println x.empty

Expected output

[Pipeline] echo

[]
[Pipeline] echo
true
[Pipeline] echo
true
[Pipeline] echo
[hello]
[Pipeline] echo
false
[Pipeline] echo
false
[Pipeline] End of Pipeline

Actual output

[Pipeline] echo

[]
[Pipeline] echo
true
[Pipeline] echo
[]
[Pipeline] echo
[hello]
[Pipeline] echo
false
[Pipeline] echo
[false]
[Pipeline] End of Pipeline

Downgrading the Pipeline:Groovy plugin to 2.47 fixes it; after upgrading again, the weird behaviour is back.

Workaround

For the moment, I can live with calling isEmpty() instead of accessing empty.

further considerations

I have not tested whether any other properties besides .empty are affected.

---
Originally reported by hjholtz, imported from: list.empty broken in pipeline scripts


  • status: Open
  • priority: Minor
  • component(s): workflow-cps-plugin
  • label(s): complex-cps-code, regression, triaged-2018-11
  • resolution: Unresolved
  • votes: 2
  • watchers: 9
  • imported: 2025-12-07

Raw content of original issue

Since upgrading to Pipeline:Groovy 2.48, the .empty property of List objects gives very strange results, whose boolean value in particular is the reverse of the expected.

When executing the following script as a pipeline (testet via "Replay" and replacing the existing script by this) gives weird output:


 Script



x = [] as List

println x
println x.isEmpty()
println x.empty
x<<"hello"
println x
println x.isEmpty()
println x.empty

Expected output



[Pipeline] echo

[]
[Pipeline] echo
true
[Pipeline] echo
true
[Pipeline] echo
[hello]
[Pipeline] echo
false
[Pipeline] echo
false
[Pipeline] End of Pipeline

Actual output



[Pipeline] echo

[]
[Pipeline] echo
true
[Pipeline] echo
[]
[Pipeline] echo
[hello]
[Pipeline] echo
false
[Pipeline] echo
[false]
[Pipeline] End of Pipeline


Downgrading the Pipeline:Groovy plugin to 2.47 fixes it; after upgrading again, the weird behaviour is back.

Workaround

For the moment, I can live with calling isEmpty() instead of accessing empty.

further considerations

I have not tested whether any other properties besides .empty are affected.

environment

```
Ubuntu 16.04.3 64bit

OpenJDK 1.8.0_151

Jenkins 2.89.4

Pipeline:Groovy 2.48
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the pipeline script from the issue with Pipeline:Groovy 2.48, then compare it with 2.47 and inspect the workflow-cps-plugin implementation and its existing tests. Done means List.empty returns the expected boolean and value behavior for both empty and non-empty lists, with regression coverage for the reported script.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, java
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.