copying: deep vs shallow copy module (clone() traps, copy constructors, serialization copy, records, defensive copies, collection copies), 17 contract tests
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b4X2xx7RrveVQU9R1N
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
== 1. Leak through the constructor ==
|
||||
leaky.size() after the caller clears its own list : 0
|
||||
|
||||
== 2. Leak through the getter ==
|
||||
leaky2.getNames() = [asha, ravi, intruder]
|
||||
|
||||
== 3. The defensive version ==
|
||||
safe.size() after the caller clears its list : 2
|
||||
safe.getNames().add(...) -> UnsupportedOperationException
|
||||
|
||||
== 4. unmodifiableList is a VIEW; List.copyOf is a SNAPSHOT ==
|
||||
source = [a, b, c]
|
||||
view = [a, b, c]
|
||||
snapshot = [a, b]
|
||||
|
||||
== 5. copyOf is shallow: the ELEMENTS are still shared ==
|
||||
frozen.get(0) = x-mutated
|
||||
Reference in New Issue
Block a user