Near the end of Chapter 2, Day 1, there is the following regarding using defensive copy to avoid calling alient methods:
This change also fixes another bug that isn’t related to concurrency—a listener can now call removeListener() within its onProgress() method without modifying the copy of listeners that’s mid-iteration.
I can see why this is true, but when would this ever be useful?
removeListener(), it probably wants to remove itself or another listener from
listeners, right? If it removes a
listenersCopy, then it likely failed to do what it intended.