Skip to main content

Practice · 2 of 3

Find the Leaked Mutability

CHALLENGE
Difficulty: intermediate+25 XP

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.

Back to lesson: Practice: Contract Lab