Fix the lock check behind thread-safety comments
Your task
A teammate ran an AI over a Java concurrency utility, and it added comments like "thread-safe: guarded by the lock above". A lock near one access proves nothing. The claim holds only if every access to the field takes the same lock. Your team checks claims like this against a log of every access.
An assistant wrote find_unguarded_fields(access_lines). It is in the editor. It has a bug. Find it and fix it.
Input and output:
access_lines: one line per access to a shared field, writtenfield|access|lock. The access isreadorwrite. The lock is the name of the lock held, ornonewhen no lock is held. Every line has exactly these three fields, and nothing is trimmed.- Return the names of the fields that are not guarded, without repeats, sorted by plain character order.
Rules the tests check:
- A field is guarded only when every access to it holds the same lock, and that lock is not
none. - So a field fails when any of its accesses holds no lock, or when two of its accesses hold different locks.
- Lock names are compared exactly, case included:
Lockandlockare different locks. - Reads count as much as writes.
Examples
find_unguarded_fields(access_lines: list[str]) -> list[str]Example 1
Input
find_unguarded_fields(["count|write|stateLock", "count|read|stateLock"])Output
[]Example 2
Input
find_unguarded_fields(["count|write|stateLock", "count|read|none"])Output
["count"]Example 3
Input
find_unguarded_fields(["total|write|lockA", "total|read|lockB"])Output
["total"]