Skip to main content

Practice ยท 2 of 3

Find the Leaked Mutability

Badge stores an internal List<String> log of scan events. The current implementation returns the internal list directly. A caller can clear() your history without your class knowing. Fix Badge so that: - the internal list can never be modified from outside - scans still accumulate internally via scan(String event) - history() returns a read-only view Keep the constructor defensive too: copy the incoming list.

Difficulty: intermediate

Back to lesson: Practice: Contract Lab