According to the documentation, a Groovy map created using Map#withDefault should add unknown keys referenced via Map#get or Map#[] to the map itself. When executing the below code snippet as a Jenkins pipeline, unknown keys will not be added to the map.
def map = [:].withDefault { [] }
map.get('A') << '1'
map['B'] << '1'
println map.toString() // prints [:], expected [A:[1], B:[1]]
println map.keySet().toString() // prints [], expected [A, B]
Running the same snippet in a regular Groovy interpreter or the Jenkins script console will result in the expected output.
Originally reported by ailuridae, imported from: Groovy Map created via Map#withDefault does not insert unknown keys
- assignee: vjuranek
- status: Open
- priority: Minor
- component(s): groovy-plugin
- resolution: Unresolved
- votes: 1
- watchers: 2
- imported: 20260604-161841
Raw content of original issue
According to the documentation, a Groovy map created using Map#withDefault should add unknown keys referenced via Map#get or Map#[] to the map itself. When executing the below code snippet as a Jenkins pipeline, unknown keys will not be added to the map.
def map = [:].withDefault { [] }
map.get('A') << '1'
map['B'] << '1'
println map.toString() // prints [:], expected [A:[1], B:[1]]
println map.keySet().toString() // prints [], expected [A, B]
Running the same snippet in a regular Groovy interpreter or the Jenkins script console will result in the expected output.
- environment:
Jenkins 2.414.1, Java 11, Groovy 2.4.21
According to the documentation, a Groovy map created using Map#withDefault should add unknown keys referenced via Map#get or Map#[] to the map itself. When executing the below code snippet as a Jenkins pipeline, unknown keys will not be added to the map.
def map = [:].withDefault { [] } map.get('A') << '1' map['B'] << '1' println map.toString() // prints [:], expected [A:[1], B:[1]] println map.keySet().toString() // prints [], expected [A, B]Running the same snippet in a regular Groovy interpreter or the Jenkins script console will result in the expected output.
Originally reported by ailuridae, imported from: Groovy Map created via Map#withDefault does not insert unknown keys
Raw content of original issue
Jenkins 2.414.1, Java 11, Groovy 2.4.21