Description
import groovy.json.internal.LazyMap def map = new LazyMap() map.someProperty = "1" map.someProperty = "2" map.someProperty = "3" println "M: ${map.size()}" // prints 3 // buildIfNeeded hasn't been called println map.someProperty // access map property, buildIfNeeded is called println "M: ${map.size()}" // prints 1
LazyMap's put() adds values to it's internal array even if it's a redundant key, which leads to size() returning an incorrect result if the LazyMap hasn't been built yet. One fix would be to have size call buildIfNeeded() before returning the size.
I ran into this after modifying json that was loaded via JsonSlurper.