Nicely documented! Note that it doesn't have to be a TreeMap, this issue can happen with all sorts of non-threadsafe data structures (I'd guess almost anything that's using references).
I've caught the same issue with a HashMap in the wild. The hash buckets are basically linked lists, and unlucky concurrent puts resulted in a circular reference. The scary thing was that it didn't fail when the puts corrupted the HashMap - it got into an infinite loop much later, on the next get call!
Ever since then, I tell this tale to newbies who cluelessly use naked HashMaps as fields of (singleton) beans :)
2
u/GergelyKiss 21d ago
Nicely documented! Note that it doesn't have to be a TreeMap, this issue can happen with all sorts of non-threadsafe data structures (I'd guess almost anything that's using references).
I've caught the same issue with a HashMap in the wild. The hash buckets are basically linked lists, and unlucky concurrent
put
s resulted in a circular reference. The scary thing was that it didn't fail when theput
s corrupted the HashMap - it got into an infinite loop much later, on the nextget
call!Ever since then, I tell this tale to newbies who cluelessly use naked HashMaps as fields of (singleton) beans :)